Issue Type: Bug Bug
Affects Versions: current
Assignee: Nicolas De Loof
Components: build-flow, core
Created: 28/Aug/14 12:54 PM
Description:

We are trying to build a "pipeline" orchestrated by a buildflow job and consisting of some "resuable" other parameterised jobs. The problem I am having is passing variables between a downstream job and the parent buildflow.

Here is the current code of a downstream job:

import com.cloudbees.plugins.flow.FlowRun
import groovy.json.JsonSlurper
import hudson.model.ParametersAction
import hudson.model.StringParameterValue

def commitMessage = build.environment.get("COMMIT_MESSAGE")
def password = build.environment.get("jenkins-read-only")

def issueKey = (commitMessage =~ $/(\p{Alpha}+-\d+).*/$)[0][1]

Authenticator.setDefault (new Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication ("jenkins-read-only", password.toCharArray())
    }
})
def issueUrl = new URL("http://jira.scansafe.cisco.com/rest/api/2/issue/${issueKey}")
def content = new BufferedReader(new InputStreamReader(issueUrl.openConnection().getContent() as InputStream))
def issue = new JsonSlurper().parse(content)
String linkedReleaseTicket = issue.fields.issuelinks.inwardIssue.key.find { it =~ /RL-/}

if(linkedReleaseTicket == null) {
    throw new IllegalStateException("Expected issue '${issueKey}' to be linked to ONE release ticket")
}

build.getCauses().each {
    FlowRun run = it.flowRun
    println(run)
    println(run.class)
    run.buildVariables.put("JIRA_TICKET", linkedReleaseTicket)
    def existingParams = (ParametersAction) run.getAction(ParametersAction.class)
    def newParams = [new StringParameterValue("JIRA_TICKET", linkedReleaseTicket)]
    if (existingParams == null) {
        run.addAction(new ParametersAction(newParams))
    } else {
        run.replaceAction(existingParams.createUpdated(newParams))
    }

printVars("env", run.environment)
printVars("var", run.buildVariables)                
}

build.environment.put("JIRA_TICKET", linkedReleaseTicket)
build.buildVariables.put("JIRA_TICKET", linkedReleaseTicket)
                
                
def void printVars(String name, def vars) {
  println("-"*32)
  println("")
  println(name + "::")
  vars.each {
    println "  ${it.key} : ${it.value}"  
  }
  println("")
  println("-"*32)
  println("")
}

                
return "Found release ticket: ${linkedReleaseTicket}"

I've tried putting it in every "environment" map possible and even the hack from StackOverflow (using the dynamic parameters) doesn't seem to work. In the child job you can see the value of the variable, but in the parent its always null.

Its as if the child got an immutable copy of the parent's environment variables, and that the child also doesn't expose any modifications of its own environment variables so that in the parent buildflow you can do something like:

releaseTicketJob = build("lookup-release-ticket", COMMIT_MESSAGE: commitMessage)
def ticket = releaseTicketJob.build.environment.get("JIRA_TICKET")

or

releaseTicketJob = build("lookup-release-ticket", COMMIT_MESSAGE: commitMessage)
def ticket = params.get("JIRA_TICKET")

Is there any way to pass this information between the child and parent job?

Thanks

Environment: Jenkins 1.570, Build flow plugin v0.12
Project: Jenkins
Priority: Major Major
Reporter: James McGivern
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira

--
You received this message because you are subscribed to the Google Groups "Jenkins Issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to