[jenkins]-pipeline 修改build name 和 description

我会带着你远行 2023-02-17 11:19 153阅读 0赞

[jenkins]-pipeline 修改build name 和 description

效果如下

format_png

流水线脚本写的有点粗糙

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

  1. // Using git without checkout
  2. pipeline {
  3. agent any
  4. parameters {
  5. gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'Branch', sortMode: 'DESCENDING_SMART', type: 'PT_BRANCH'
  6. }
  7. stages {
  8. stage('更新拉取最新代码') {
  9. steps {
  10. git branch: "${params.Branch}", url: 'git@gitlab.ihaozhuo.com:Java_Service/YJK-Java.git'
  11. }
  12. }
  13. stage('输出项目的参数') {
  14. steps {
  15. sh "echo ${WORKSPACE} "
  16. sh "echo ${Branch} "
  17. //sh "echo ${deploy_step} "
  18. sh "echo ${env.JOB_NAME} "
  19. script {
  20. //设置buildName
  21. wrap([$class: 'BuildUser']) {
  22. def deploylog="${BUILD_USER} use pipeline '${JOB_NAME}(${BUILD_NUMBER})' "
  23. println deploylog
  24. buildName "#${BUILD_NUMBER}-^${BRANCH}^-${BUILD_USER}"
  25. //输出最新一次提交信息
  26. HTTPD_LOCATION= sh( returnStdout: true, script: 'git show -s |grep -vE "commit|Date" |grep -v "^$"')
  27. //修改Description"
  28. buildDescription "${HTTPD_LOCATION}"
  29. }
  30. }
  31. script
  32. {
  33. switch(Model)
  34. {
  35. case "all":
  36. sh "echo \u001B[31m部署全部模块\u001B[0m !!!"
  37. default:
  38. sh "echo others"
  39. }
  40. }
  41. }
  42. }
  43. }
  44. }
  45. node {
  46. //时间插件
  47. timestamps {
  48. env.PRO_TYPE = "test"
  49. //颜色插件
  50. ansiColor('xterm') {
  51. stage('Java编译') {
  52. sh "echo ${WORKSPACE} "
  53. sh "echo ${Branch} "
  54. //sh "echo ${deploy_step} "
  55. sh "echo ${env.JOB_NAME} "
  56. script
  57. {
  58. switch(Model)
  59. {
  60. case "all":
  61. sh "echo \u001B[31m部署全部模块\u001B[0m !!!"
  62. 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"
  63. default:
  64. sh "echo 部署 \u001B[32m $Model \u001B[0m !!!"
  65. 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"
  66. }
  67. }
  68. }
  69. stage('构建镜像预发布') {
  70. sh "echo ${Model}"
  71. sh "echo ${WORKSPACE} "
  72. sh "echo ${env.PRO_TYPE} "
  73. //sh "echo ${deploy_step} "
  74. sh "echo ${BUILD_NUMBER} "
  75. sh "sh /srv/deploy_scripts/deploy.sh $Model $WORKSPACE ${env.PRO_TYPE} $BUILD_NUMBER"
  76. sh "echo build successful"
  77. }
  78. }
  79. }
  80. }

参考

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

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

发表评论

表情:
评论列表 (有 0 条评论,153人围观)

还没有评论,来说两句吧...

相关阅读

    相关 JetCache动态修改name

    背景 公司因为自己封装的redisUtils查询缓慢,换用了阿里JetCache。由于目前公司基础架构组尚未提供一些查询线上数据的redis小工具,故决定自己封装一个。 J