【发布时间】:2019-04-09 17:56:37
【问题描述】:
我有一个 Jenkins 管道,它针对几台服务器运行 ansible playbook
node {
stage('Get Playbook') {
dir('ansible-dir') {
git branch: 'master',
credentialsId: 'creds',
url: 'ssh://git@gitserver.com'
}
}
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'ansible', usernameVariable: 'username', passwordVariable: 'password']]){
def remote = [:]
remote.name = 'Remote Ansible Server'
remote.host = 'server.domain.com'
remote.user = username
remote.password = password
remote.allowAnyHosts = true
stage('Copy dir to remote server'){
sshPut remote: remote, from: '/localdir', into: '/home/remote/jenkins'
}
stage('Run ansible playbook'){
sshCommand remote: remote, command: 'ANSIBLE_CONFIG=/home/remote/jenkins/ansible.cfg ansible-playbook /home/remote/jenkins/playbook.yml -vvv'
}
stage('Copy report to local machine') {
sshGet remote: remote, from: '/home/remote/jenkins/reports', into: '/home/user/reports', override: true
}
}
我遇到的问题是“将报告复制到本地机器”阶段并不总是运行。有时,服务器会在播放回顾中失败,这本身不是问题,因为剧本中生成的报告说明了这一点,并且有日志记录来识别它。
问题是当服务器在回放中失败时,jenkins 会给出以下错误。
org.hidetake.groovy.ssh.session.BadExitStatusException: Command returned exit status 2: ANSIBLE_CONFIG=/home/remote/jenkins/ansible.cfg ansible-playbook /home/remote/jenkins/playbook.yml -vvv
这会阻止管道中的下一个阶段运行。有没有办法抑制这个错误输出,以便管道继续?
【问题讨论】: