Pipeline plugin to access variable set in job in another job

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Pipeline plugin to access variable set in job in another job

Johann Muller
With the current flow plugin I can do the following:

  api = build("upload-files",VERSION_TO_DEPLOY:params["API_VERSION”]))

  build("deploy-files", ARTIFACT_TO_DEPLOY:api.environment.get("ARTIFACT_TO_DEPLOY") )


This is just a simplified version, as the deploy job has 5 blocks of these. All 5  upload-files job runs concurrently and then runs sequentially through all 5 of them.  The upload-files job generates a file with a certain file name based on the package (not shown in the example for simplicity) and the version supplied. This filename gets set to the "ARTIFACT_TO_DEPLOY" variable with another plugin.


Now my question is can the pipeline plugin also support this?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/d17bb5e8-84c9-455d-9bae-413e9fd0f675%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Pipeline plugin to access variable set in job in another job

Johann Muller
So I figured out how to do this, I wrote a function that will return the value of the variable that is required. First parameter is the jenkins job, then its the build number of the job that you require and finally the variable name,

def getJobVariable(jobName,buildId,varName){ 
job = Jenkins.instance.getItemByFullName(jobName)
        newJob = job.getBuildByNumber(buildId)
  return newJob.getEnvVars().get(varName,null)
}


api = build job: 'PipelineVarTest'
buildID =  api.getNumber()
echo getJobVariable('PipelineVarTest',15,'ARTIFACT_TO_DEPLOY')

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/98b938e9-7a8f-4e3b-8b0f-c173c68d741d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Pipeline plugin to access variable set in job in another job

akostadinov-2

On Friday, February 19, 2016 at 3:55:57 PM UTC+2, Johann Muller wrote:
...
  return newJob.getEnvVars().get(varName,null)
... 

Thank you for the useful pointers. FYI `getEnvVars` not very reliable. I wanted to get in this way but what I've got is only the first line of the string for some reason. Also `getEnvVars` is deprecated. I actually wanted to get a variable that was set by a parameter. So I ended up doing:

>    paramValue = build.allActions.
>        find {it in hudson.model.ParametersAction}.
>        getParameter("MY_PARAM_NAME").
>        value

Regards.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/b588d086-1f5c-4cce-aa2d-29b34c0cee13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.