[jenkins]-pipeline 修改build name 和 description

效果如下

流水线脚本写的有点粗糙

哪里修改build name 和 description 均备注了

// Using git without checkout 
pipeline {
  agent any
  parameters {
    gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'Branch', sortMode: 'DESCENDING_SMART', type: 'PT_BRANCH'
  }

  stages {
    stage('更新拉取最新代码') {
      steps {
        git branch: "${params.Branch}", url: 'git@gitlab.ihaozhuo.com:Java_Service/YJK-Java.git'
      }
    }
    stage('输出项目的参数') {
      steps {
        sh "echo ${WORKSPACE} "
        sh "echo ${Branch} "
        //sh "echo ${deploy_step} "
        sh "echo ${env.JOB_NAME} "
        script {
            //设置buildName
            wrap([$class: 'BuildUser']) {
            def deploylog="${BUILD_USER} use pipeline  '${JOB_NAME}(${BUILD_NUMBER})' "
            println deploylog
            buildName "#${BUILD_NUMBER}-^${BRANCH}^-${BUILD_USER}"
            //输出最新一次提交信息
            HTTPD_LOCATION= sh(  returnStdout: true, script: 'git show -s  |grep -vE "commit|Date" |grep -v "^$"')
            //修改Description"
            buildDescription "${HTTPD_LOCATION}" 
            }
        }
        script
        {
            switch(Model)
            {
                case "all":
                    sh "echo \u001B[31m部署全部模块\u001B[0m !!!"
                default:
                    sh "echo others"
            
        }
        }
            }

      }
    }

  }
node {
    //时间插件
    timestamps {
    env.PRO_TYPE = "test"
    //颜色插件
    ansiColor('xterm') {
    stage('Java编译') { 
        sh "echo ${WORKSPACE} "
        sh "echo ${Branch} "
        //sh "echo ${deploy_step} "
        sh "echo ${env.JOB_NAME} "
        script
        {
            switch(Model)
            {
                case "all":
                    sh "echo \u001B[31m部署全部模块\u001B[0m !!!"
                    sh "cd ${WORKSPACE} && rm dev-properties/ -rf && git clone git@gitlab.ihaozhuo.com:dev-properties/dev-properties.git  &&  cd ${WORKSPACE}/haozhuo/ && mvn clean install -T 1C -Dmaven.test.skip=true  -Dmaven.compile.fork=true -Ptest -Dautoconfig.userProperties=${WORKSPACE}/dev-properties/test1.properties -Dautoconfig.charset=utf-8 -Dautoconfig.interactive=off"
                default:
                    sh "echo 部署  \u001B[32m $Model \u001B[0m !!!"
                    sh "cd ${WORKSPACE} && rm dev-properties/ -rf && git clone git@gitlab.ihaozhuo.com:dev-properties/dev-properties.git  &&  cd ${WORKSPACE}/haozhuo/ && mvn clean install  -pl $model -am -U  -T 1C -Dmaven.test.skip=true  -Dmaven.compile.fork=true -Ptest -Dautoconfig.userProperties=${WORKSPACE}/dev-properties/test1.properties -Dautoconfig.charset=utf-8 -Dautoconfig.interactive=off"
            
        }
        }
   }
    stage('构建镜像预发布') { 
        sh "echo ${Model}"
        sh "echo ${WORKSPACE} "
        sh "echo ${env.PRO_TYPE} "
        //sh "echo ${deploy_step} "
        sh "echo ${BUILD_NUMBER} "
        sh "sh /srv/deploy_scripts/deploy.sh $Model $WORKSPACE ${env.PRO_TYPE}  $BUILD_NUMBER"
        sh "echo build successful"

   }


}
}

}



参考

https://plugins.jenkins.io/build-name-setter/

https://blog.csdn.net/a910196454/article/details/106375630/

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐