Jenkins - How to get and use upstream info in downstream

前端 未结 5 1472
我在风中等你
我在风中等你 2020-12-25 15:15

Executing upstream job called \"A\". On success of A executing test cases which is downstream project \"B\". But while sending mail from B we have to incorporate upstream pr

5条回答
  •  清酒与你
    2020-12-25 16:02

    Extending @razboy answer: this is good way if Cause cannot be whitelisted in sandbox. I forgot about Jenkins API and used current build console to look for string about trigger cause. You can try to fetch data from API as @razboy or get current console and grep it if you need simple stuff. Jenkins API is more flexible for more complex logic. To get API help,append /api to your build url: /job///api

       def buildUrl = env.BUILD_URL
       sh "wget $buildUrl -O currentConsole.txt"
       statusCode = sh returnStatus: true,script: 'cat currentConsole.txt | grep -q "Started by upstream project"'
       boolean startedByUpstream= statusCode==0
    

提交回复
热议问题