使用sudo权限执行docker命令

This commit is contained in:
zhouxiunai
2019-04-28 14:41:56 +08:00
parent d4202bec94
commit c611ab2bc7
+4 -4
View File
@@ -53,13 +53,13 @@ pipeline {
steps {
withCredentials([sshUserPrivateKey(credentialsId: "${env.credentialsId}", keyFileVariable: 'kfIdentity', passphraseVariable: 'pVariable', usernameVariable: 'userName')]) {
sshCommand(remote: [ name: "${env.deployName}" ,host: "${env.deployHost}" ,allowAnyHosts: true,user: "${userName}",identityFile: "${kfIdentity}" ] ,
command: "docker stop ${env.containerName}",sudo: false ,failOnError: false)
command: "docker stop ${env.containerName}",sudo: true ,failOnError: false)
sshCommand(remote: [ name: "${env.deployName}" ,host: "${env.deployHost}" ,allowAnyHosts: true,user: "${userName}",identityFile: "${kfIdentity}" ] ,
command: "docker rm ${env.containerName}",sudo: false ,failOnError: false)
command: "docker rm ${env.containerName}",sudo: true ,failOnError: false)
sshCommand(remote: [ name: "${env.deployName}" ,host: "${env.deployHost}" ,allowAnyHosts: true,user: "${userName}",identityFile: "${kfIdentity}" ] ,
command: "docker rmi ${env.dockerRegistry}/${env.GROUP}/${env.ARTIFACTID}:${env.VERSION}",sudo: false ,failOnError: false)
command: "docker rmi ${env.dockerRegistry}/${env.GROUP}/${env.ARTIFACTID}:${env.VERSION}",sudo: true ,failOnError: false)
sshCommand(remote: [ name: "${env.deployName}" ,host: "${env.deployHost}" ,allowAnyHosts: true,user: "${userName}",identityFile: "${kfIdentity}" ] ,
command: "docker run -d -p ${env.export}:8080 --name ${env.containerName} ${env.dockerRegistry}/${env.GROUP}/${env.ARTIFACTID}:${env.VERSION}",sudo: false ,failOnError: true)
command: "docker run -d -p ${env.export}:8080 --name ${env.containerName} ${env.dockerRegistry}/${env.GROUP}/${env.ARTIFACTID}:${env.VERSION}",sudo: true ,failOnError: true)
}
}
}