Pipeline plugin to access variable set in job in another job

327 visualizações
Pular para a primeira mensagem não lida

Johann Muller

não lida,
17 de fev. de 2016, 11:19:4217/02/2016
para Jenkins Users
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?

Johann Muller

não lida,
19 de fev. de 2016, 08:55:5719/02/2016
para Jenkins Users
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')

akostadinov

não lida,
24 de nov. de 2017, 16:58:2324/11/2017
para Jenkins Users

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.
Responder a todos
Responder ao autor
Encaminhar
0 nova mensagem