0


jenkins pipeline 指定执行节点

第一种写法:
pipeline {
agent {
label “slave-hw”
}
stages {
stage(‘执行更新程序包’) {
steps {
sh ‘cd /apps/nedy/nedy/csctbb/HWCLOUD ; sh test.sh’
}
}
stage(‘是否继续’) {
steps {
input message: ‘确认继续吗?’, ok: ‘确认’
}
}
stage(‘继续’) {
steps {
sh ‘cd /apps/nedy/nedy/csctbb/HWCLOUD ; sh test1.sh’
}
}
}
}


第二种写法:(失败)

node(“slave-hw”){
stages {
stage(‘测试’) {
steps {
sh ‘cd /apps/nedy/nedy/csctbb/HWCLOUD ; sh test.sh’
}
}
stage(‘是否继续’) {
steps {
input message: ‘确认继续吗?’, ok: ‘确认’
}
}
stage(‘继续’) {
steps {
sh ‘cd /apps/nedy/nedy/csctbb/HWCLOUD ; sh test1.sh’
}
}
}
}

==============================---------------
#以上构建的pipeline脚本:
node(“node1”){
stage(“clone code”){
sh ‘rm -rf /var/lib/nedy/workspace/pipeline-job/*’
git branch: ‘develop’, credentialsId: ‘1f60339e-fbb3-41e6-66a7-ae80334823b2’, url: ‘git@192.168.10.4:va/web01-page.git’
}
stage(“compress code”){
sh ‘cd /var/lib/nedy/workspace/pipeline-job/ && tar cvf index_code.tar.gz
}
stage(“send code”){
sh ‘ssh 192.168.10.4 “/usr/sbin/nginx -s stop”’
sh 'ssh 192.168.10.4 "rm -rf /apps/nginx/html/
"’
sh ‘scp /var/lib/nedy/workspace/pipeline-job/index_code.tar.gz 192.168.1.23:/apps/nginx/html’
}
stage(“deploy code”){
sh ‘ssh 192.168.10.4 “cd /apps/nginx/html/ && tar xvf index_code.tar.gz”’
sh ‘ssh 192.168.10.4 “/usr/sbin/nginx”’
}
}

------第三种写法

pipeline {
agent {label ‘slave-hw’ }
stages {
stage(‘test’) {
steps {
dir(‘/apps/nedy/nedy/csctbb/HWCLOUD’){
sh ‘sh test.sh’
}
}
}
stage(‘是否继续’) {
steps {
input message: ‘确认继续吗?’, ok: ‘确认’
}
}
stage(‘继续’) {
steps {
dir(‘/apps/nedy/nedy/csctbb/HWCLOUD’){
sh ‘sh test1.sh’
}
}
}
}
}

标签: jenkins git github

本文转载自: https://blog.csdn.net/tongzidane/article/details/128421435
版权归原作者 吕楚王 所有, 如有侵权,请联系我们删除。

“jenkins pipeline 指定执行节点”的评论:

还没有评论