Example secret file and sshagent
Example using a secret file as a variable and sshagent
node{
stage('CertCheck'){
withCredentials([file(credentialsId: '19df427c-0000-1234-9876-161969d46b18', variable: 'pemfile')]) {
sh 'ls -ahl'
echo "${pemfile}"
sh "cat ${pemfile}"
}
}
stage('SSHSomething'){
sshagent(['c4cc169b-aaaa-bbbb-ffff-543a157f6ad5']) {
sh "ssh user@ssh.example.com 'ifconfig'"
}
}
}
Stage CertCheck
[in_jenkins-dsl-test_hw_test-L6OPGZSILNYU4LFJKDMY4AGUBMSB2FT3Z3UAW66ODUIPZN4WUNBA] Running shell script
+ ls -ahl
total 33K
drwxr-xr-x 2 jenkins jenkins 2 Sep 8 21:03 .
drwxr-xr-x 28 jenkins jenkins 28 Sep 9 01:52 ..
****
[in_jenkins-dsl-test_hw_test-L6OPGZSILNYU4LFJKDMY4AGUBMSB2FT3Z3UAW66ODUIPZN4WUNBA] Running shell script
+ cat ****
-----BEGIN CERTIFICATE-----
MIID/DCCAuSgAwIBAgIBSzANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx
EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM
GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx
GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUyMjAzNTBaFw0y
MDAzMDUyMjAzNTBaMIGPMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv
bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl
cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEgMB4GA1UEAwwXQW1hem9uIFJE
UyB1cy13ZXN0LTIgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDM
H58SR48U6jyERC1vYTnub34smf5EQVXyzaTmspWGWGzT31NLNZGSDFaa7yef9kdO
mzJsgebR5tXq6LdwlIoWkKYQ7ycUaadtVKVYdI40QcI3cHn0qLFlg2iBXmWp/B+i
Z34VuVlCh31Uj5WmhaBoz8t/GRqh1V/aCsf3Wc6jCezH3QfuCjBpzxdOOHN6Ie2v
xX09O5qmZTvMoRBAvPkxdaPg/Mi7fxueWTbEVk78kuFbF1jHYw8U1BLILIAhcqlq
x4u8nl73t3O3l/soNUcIwUDK0/S+Kfqhwn9yQyPlhb4Wy3pfnZLJdkyHldktnQav
9TB9u7KH5Lk0aAYslMLxAgMBAAGjZjBkMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMB
Af8ECDAGAQH/AgEAMB0GA1UdDgQWBBT8roM4lRnlFHWMPWRz0zkwFZog1jAfBgNV
HSMEGDAWgBROAu6sPvYVyEztLPUFwY+chAhJgzANBgkqhkiG9w0BAQUFAAOCAQEA
JwrxwgwmPtcdaU7O7WDdYa4hprpOMamI49NDzmE0s10oGrqmLwZygcWU0jT+fJ+Y
pJe1w0CVfKaeLYNsOBVW3X4ZPmffYfWBheZiaiEflq/P6t7/Eg81gaKYnZ/x1Dfa
sUYkzPvCkXe9wEz5zdUTOCptDt89rBR9CstL9vE7WYUgiVVmBJffWbHQLtfjv6OF
NMb0QME981kGRzc2WhgP71YS2hHd1kXtsoYP1yTu4vThSKsoN4bkiHsaC1cRkLoy
0fFA4wpB3WloMEvCDaUvvH1LZlBXTNlwi9KtcwD4tDxkkBt4tQczKLGpQ/nF/W9n
8YDWk3IIc1sd0bkZqoau2Q==
-----END CERTIFICATE-----
Stage SSHSomething
[in_jenkins-dsl-test_hw_test-L6OPGZSILNYU4LFJKDMY4AGUBMSB2FT3Z3UAW66ODUIP99999999] Running shell script
+ ssh user@ssh.example.com ifconfig
lo0: flags=8049<up,loopback,running,multicast> metric 0 mtu 16384
options=600003<rxcsum,txcsum,rxcsum_ipv6,txcsum_ipv6>
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
nd6 options=21<performnud,auto_linklocal>
groups: lo
epair1b: flags=8843<up,broadcast,running,simplex,multicast> metric 0 mtu 1500
options=8<vlan_mtu>
ether 01:23:45:67:89:ab
inet 172.69.100.163 netmask 0xffff0000 broadcast 172.69.255.255
nd6 options=9<performnud,ifdisabled>
media: Ethernet 10Gbase-T (10Gbase-T <full-duplex>)
status: active
groups: epair
</full-duplex></performnud,ifdisabled></vlan_mtu></up,broadcast,running,simplex,multicast></performnud,auto_linklocal></rxcsum,txcsum,rxcsum_ipv6,txcsum_ipv6></up,loopback,running,multicast>