how to get $CAUSE in workflow

后端 未结 9 1736
暗喜
暗喜 2020-12-10 01:24

Jenkins has a $CAUSE variable available to freestyle build jobs.

How can I access this or something similar in workflow?

My team makes use of it in email out

9条回答
  •  我在风中等你
    2020-12-10 02:10

    Looks like as of Jenkins 2.22 (JENKINS-41272), you can access the currentBuild.getBuildCauses() method to get an array of build causes. For example:

    environment {
      CAUSE = "${currentBuild.getBuildCauses()[0].shortDescription}"
    }
    
    steps {
      echo "Build caused by ${env.CAUSE}"
    }
    

提交回复
热议问题