我创建了一个 Jenkins 管道任务并使用 Git 来维护 Jenkinsfile。项目的目录结构为:
詹金斯文件:
pipeline {
stages {
stage('Deploy') {
steps {
// 部署到目标服务器
echo "deploy: ${server}"
script {
withCredentials([sshUserPrivateKey(credentialsId: serverAuth, keyFileVariable: 'identity', usernameVariable: 'username')]) {
def remote = [:]
remote.name = 'backend'
remote.host = server
remote.port = 22
remote.allowAnyHosts = true
remote.user = username
remote.identityFile = identity
// 删除旧脚本文件
sshCommand remote: remote, command: 'rm -f /tmp/deploy.sh'
// 上传脚本文件
sshPut remote: remote, from: 'shell/deploy.sh', into: '/tmp/'
// 运行部署服务脚本文件
sshCommand remote: remote, command: 'bash /tmp/deploy.sh ${Project_name} ${imageTag}'
}
}
}
}
}
}
到了某个阶段,将shell/deploy.sh文件发送到目标服务器,并执行脚本文件。
执行结果错误:java.lang.IllegalArgumentException: /var/jenkins_home/workspace/web-pipeline/shell/deploy.sh 不存在。
如何找到目标文件:shell/deploy.sh?
我不知道
。
默认签出在存储库的根文件夹中运行管道,而不是在 Jenkinsfile 所在的文件夹中,因此路径将为
'maven/shell/deploy.sh'
或 'node/shell/deploy.sh'