我试图通过WebHook连接Jenkins和Gitlab。当我推送特定分支时,webhook调用jenkins管道。每个构建都有一个描述,并打印“Started by GitLab push by XXX”。现在我有一个问题,我能自己改那个词吗?我想把它改成我想要的。例如,git commit message或合并请求中的其他内容。请告诉我!真诚的。我试图在stackoverflow和谷歌搜索,但我没有得到适当的方式来控制它。所以我在这里留了张纸条。
zlhcx6iw1#
是的,当GitLab webhook触发时,您可以在Jenkins中更改构建描述。要做到这一点,您需要向Jenkins管道脚本添加一些额外的参数,以允许您指定自定义构建描述。
pipeline { agent any stages { stage('Build') { steps { sh 'echo "Build started"' } } } post { always { // Set custom build description based on git commit message def customDescription = sh (script: 'git log -1 --pretty=%B', returnStdout: true).trim() // Use the custom description if available, otherwise use default message currentBuild.description = customDescription ?: "Started by GitLab push by ${env.GITLAB_USER_LOGIN}" } } }
1条答案
按热度按时间zlhcx6iw1#
是的,当GitLab webhook触发时,您可以在Jenkins中更改构建描述。要做到这一点,您需要向Jenkins管道脚本添加一些额外的参数,以允许您指定自定义构建描述。