【发布时间】:2018-07-01 05:00:12
【问题描述】:
我有一个 jenkins 实例在我的树莓派 3 上运行,我的(简单)apache 网络服务器也在同一个树莓派上运行。
我有一个来自 jenkins 的管道来获取一个 git repo,构建它并(通过 scp)将构建文件放在我的网络服务器上。
我有一个 ssh 私钥/公钥设置,但是当 jenkins 托管在具有相同 IP 地址的同一“机器”上时,拥有一个 ssh 密钥有点愚蠢(?)?
无论如何,在我的树莓派上,我已经设置了自动密钥文件和带有公钥的已知主机文件,并且我已经通过 ssh-agent 插件将私钥添加到 jenkins。
这里有我的 jenkins 文件,jenkins 使用它来定义我的管道:
node{
stage('Checkout') {
checkout scm
}
stage('install') {
nodejs(nodeJSInstallationName: 'nodeJS10.5.0') {
sh "npm install"
}
}
stage('build'){
nodejs(nodeJSInstallationName: 'nodeJS10.5.0') {
sh "npm run build"
}
}
stage('connect ssh and remove files') {
sshagent (credentials: ["0527982f-7794-45d0-99b0-135c868c5b36"]) {
sh "ssh pi@123.456.789.123 -p 330 rm -rf /var/www/html/*"
}
}
stage('upload new files'){
sshagent (credentials: ["0527982f-7794-45d0-99b0-135c868c5b36"]) {
sh "scp -P 330 -r ./build/* pi@123.456.789.123:/var/www/html"
}
}
}
这是失败的倒数第二个作业的输出:
[Pipeline] }
[Pipeline] // nodejs
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (connect ssh and remove files)
[Pipeline] sh
[Deploy_To_Production] Running shell script
+ ssh pi@123.456.789.123 -p 330 rm -rf /var/www/html/asset-manifest.json /var/www/html/css /var/www/html/favicon.ico /var/www/html/fonts /var/www/html/images /var/www/html/index.html /var/www/html/manifest.json /var/www/html/service-worker.js /var/www/html/static /var/www/html/vendor
Host key verification failed.
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 255
Finished: FAILURE
注意:出于安全原因,我更改了 IP 地址和 ssh 端口。
我可以手动 ssh 到我的树莓派,我可以从我的笔记本电脑手动执行命令(来自同一个域和其他域的作品)。
我还端口转发了本地 ip,以便我不在家时通过 SSH 连接到它。
我猜我在 SSH 密钥等方面做错了,但我不是专家!
谁能帮忙?
【问题讨论】:
-
为了以后参考,这里最好使用rsync
标签: jenkins ssh jenkins-pipeline