This document describes how to use SSH in Continuous Integration.
Before configuring the CODING Continuous Integration (CODING-CI) build environment, you must activate the CODING DevOps service for your Tencent Cloud account.
When executing a build in Continuous Integration, you may need to log in to a remote server with SSH protocol to execute the necessary script or command. Go to Continuous Integration > "Build Plan Settings" > "Process Configuration", use the text editor to enter the relevant command.
CODING-CI allows you to control a remote server using SSH commands.
The following example shows how to use an account and password to connect to a remote server and run SSH commands. An example of a Jenkinsfile configuration is as follows:
def remote = [:]
remote.name = "node"
remote.host = "node.abc.com"
remote.allowAnyHosts = true
node {
withCredentials([usernamePassword(credentialsId: 'sshUserAcct',
passwordVariable: 'password', usernameVariable: 'userName')]) {
remote.user = userName
remote.password = password
stage("SSH Steps Rocks!") {
writeFile file: 'test.sh', text: 'ls'
sshCommand remote: remote,
command: 'for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done'
sshScript remote: remote, script: 'test.sh'
sshPut remote: remote, from: 'test.sh', into: '.'
sshGet remote: remote, from: 'test.sh', into: 'test_new.sh', override: true
sshRemove remote: remote, path: 'test.sh'
}
}
}
Besides using an account and password to connect to a remote server, you can also use an SSH private key to connect to a remote service. An example of a Jenkinsfile configuration is as follows:
def remote = [:]
remote.name = "node"
remote.host = "node.abc.com"
remote.allowAnyHosts = true
node {
withCredentials([sshUserPrivateKey(credentialsId: 'sshUser', keyFileVariable: 'identity')]) {
// SSH login username
remote.user = 'root'
// Private key file address
remote.identityFile = identity
stage("SSH Steps Rocks!") {
writeFile file: 'abc.sh', text: 'ls'
sshCommand remote: remote,
command: 'for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done'
sshPut remote: remote, from: 'abc.sh', into: '.'
sshGet remote: remote, from: 'abc.sh', into: 'bac.sh', override: true
sshScript remote: remote, script: 'abc.sh'
sshRemove remote: remote, path: 'abc.sh'
}
}
}
Was this page helpful?