Jenkins pipeline的语法实例介绍及踩坑记录

本文介绍一下Jenkins pipeline的语法实例介绍及踩坑记录
废话不多说,直接上案例

pipeline{
    agent any
    stages {
        stage('download') {
            steps{
                echo 'This is a build step'
                git credentialsId: '0c3d0852-8a03-42e2-a893-a445308a257b', url: 'http://192.168.0.6/softwaredevelopment/eduplat.git'
            }
        }
        stage('buildUI') {
            steps{
                sh label: '', script: 'cd /data/workspace/eduPlat/ui && yarn run build'
                sh label: '', script: 'rm -rf /usr/share/nginx/html/*'
                sh label: '', script: 'mv -f /data/workspace/eduPlat/ui/dist/* /usr/share/nginx/html/'
            }
        }
        stage('killjava') {
            steps{
                echo 'This is a stop jeecg-boot-module-system-2.1.4.jar'
                sh label: '', script: 'BUILD_ID=DONTKILLME'
                sh label: '', script: 'ps -ef | grep "java -jar eduplat-boot-module-system-2.1.4.jar"| grep -v grep|awk \'{print $2}\' | xargs kill -9'
            }
        }
        stage('buildBOOT') {
            steps{
                echo 'This is a build boot step'
                sh label: '', script: 'sh /opt/buildBOOT.sh'
            }
        }
        stage('start java') {
            steps{
                echo 'This is a deploy step'
                sh label: '', script: 'source /etc/profile'
                sh label: '', script: 'sh /opt/startjar.sh'
                sh label: '', script: 'nginx -s reload'
            }
        }
    }
}

说明:
1、stage('download') 这步中, git credentialsId的编码来自http://{ip}/job/eduPlat/pipeline-syntax/语法流水线
Jenkins pipeline的语法实例介绍及踩坑记录
2、 stage('buildUI')这步中,
sh label: '', script: 'cd /data/workspace/eduPlat/ui && yarn run build'来自于
Jenkins pipeline的语法实例介绍及踩坑记录
其他也是以此类推
3、划重点。 stage('start java') 这步中,我采用了脚本的形式

source /etc/profile
export JENKINS_NODE_COOKIE=dontKillMe
cd /data/workspace/eduPlat/eduplat-boot/eduplat-boot-module-system/target/
nohup java -Dhudson.util.ProcessTree.disable=true -jar eduplat-boot-module-system-2.1.4.jar > eduplat-boot-module-system-2.1.4.out 2>&1 &

(1)export JENKINS_NODE_COOKIE=dontKillMe很重要,pipeline在退出node{}的时候,会默认清理自己发出的每个shell命令,即使使用了nohup。
(2)后台执行java程序,一定要加上{-Dhudson.util.ProcessTree.disable=true}
这个参数,否则pipeline执行完成后,java也就自动退出了。
(3)为什么我采用脚本的方式进行这个命令的执行呢?因为cd 和 nohup要是在pipeline中执行的话,不能采用两个step的形式,必须合成为一条,用&&。pipeline默认这是两个不同的命令。但是合成一条命令的话,就又太长了。所以我直接写在脚本中,也便于查找问题

划重点:欢迎点赞(#^.^#)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值