How to get the BUILD_USER in Jenkins when job triggered by timer?

后端 未结 14 1606
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 03:01

I wanted to show the user who triggered a Jenkins job in the post job email. This is possible by using the plugin Build User Vars Plugin and the env variable

14条回答
  •  南笙
    南笙 (楼主)
    2020-12-09 03:26

    For declarative pipeline syntax, here is a quick hack, base on @Kevin answer. For declarative pipeline you need to enclose them in a node, else you will get an error/ build failure

    node {
        def BUILD_FULL = sh (
            script: 'curl --silent '+buildURL+' | tr "{}" "\\n" | grep -Po \'"shortDescription":.*?[^\\\\]"\' | cut -d ":" -f2',
            returnStdout: true
            )
    
        slackSend channel: '#ci-cd',
              color: '#000000',
              message: "The pipeline was ${BUILD_FULL}  ${GIT_COMMIT_MSG} "
    
    }
    

    The output will be slack notification sent to your slack channel with the git short description

提交回复
热议问题