Return parameters/results from a job(triggered by pipeline) back to the same pipeline

后端 未结 6 1818
青春惊慌失措
青春惊慌失措 2020-12-09 09:18

Jenkins pipeline: I have a pipeline p1 that triggers a job j1 and then job j2. I want some parameters that are set by j1

6条回答
  •  臣服心动
    2020-12-09 09:32

    It can be done using "env". If you manage to make j1 add its information into the build's env.

    If j1 was a pipeline you could to env.MYKEY=MYVALUE. For a freestyle-job it should work using the EnvInject plugin (didn't try). In p1 then you will get a map with that information if you out of the build result.

    So, if you do in p1 something line this:

    // somewhere in your pipeline, i.e. p1:
    def j1BuildResult = build job: 'J1'
    def j1EnvVariables = j1BuildResult.getBuildVariables();
    

    then j1EnvVariables will be a map containing the variables you set in j1.

    PS: how to pass that info to as parameters p2 is e.g. covered here.

提交回复
热议问题