问题:
我使用sshPublisher
构建步骤运行bash脚本作为部署的一部分。该脚本的一部分是使用netstat
(和grep
/ awk
)查找进程ID。当我登录VM并手动运行脚本时,会终止进程,但是通过Jenkins部署作业,它不会
Jenkins服务器(VM1):
stage('deploy'){
sshPublisher(publishers: [sshPublisherDesc(configName: 'fdpdeploy', transfers: [sshTransfer(excludes: '', execCommand: './deploy.sh', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: 'target', sourceFiles: 'target/fdp-0.0.1-SNAPSHOT.war')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
VM2:这是脚本deploy.sh
#!/bin/bash
processId=$(sudo netstat -plten | grep 9030 | awk {'print $9}' | awk -F '/' {'print $1'})
echo $processId
kill -9 $processId
sleep 5
echo 'Starting FDP app'
nohup java -jar /data/fdp-0.0.1-SNAPSHOT.war &> /data/logs/FDPBizApp.log &
exit 0
fi
答案 0 :(得分:0)
根据您在评论中发布的输出,这就是问题所在:
sudo: sorry, you must have a tty to run sudo
(这是OP的解决方案):
使用visudo
修改sudoers
文件并注释掉requiretty
条目
Publish Over SSH插件的features列表包含以下项目:
启用命令/脚本在伪TTY
中执行
您可以通过将usePty: true
添加到发布商的sshTransfer
块来启用此功能。您的Jenkinsfile
步骤应如下所示:
stage('deploy'){
sshPublisher(publishers: [sshPublisherDesc(configName: 'fdpdeploy', transfers: [sshTransfer(excludes: '', execCommand: './deploy.sh', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: 'target', sourceFiles: 'target/fdp-0.0.1-SNAPSHOT.war', usePty: true)], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
现有步骤的唯一变化是在, usePty: true
sourceFiles: