[workflow-plugin] Recommended way to set Slave EnvVar?

51 views
Skip to first unread message

Timothy Wojtaszek

unread,
Feb 27, 2015, 3:10:38 PM2/27/15
to jenkins...@googlegroups.com
It states here:
https://github.com/jenkinsci/workflow-plugin/blob/master/TUTORIAL.md
that:
"environment variable overrides are currently limited to being global to a workflow run, not local to the current thread (and thus slave)."

Until this changes, what is the recommended approach?

Just collect them and add them to every sh command?

like this:

def localEnv = []
def golang = tool name: 'Go 1.2.2', type: 'org.jenkinsci.plugins.golang.GolangInstallation'
localEnv.add("export GOROOT=${golang}")
localEnv.add("export PATH=\$PATH:${golang}/bin")
...

sh localEnv.join("\n") + "go build ...."


Cheers,
tim

Jesse Glick

unread,
Mar 19, 2015, 11:18:57 AM3/19/15
to jenkins...@googlegroups.com
On Friday, February 27, 2015 at 3:10:38 PM UTC-5, Timothy Wojtaszek wrote:
Just collect them and add them to every sh command?

Yes, though I would suggest a more readable

def golang = tool name: 'Go 1.2.2', type: 'org.jenkinsci.plugins.golang.GolangInstallation'
def go(cmd) {
    sh "GOROOT=${golang} ${golang}/bin/go ${cmd}"
}
go 'build …'

There are two basic avenues for improvement. First, https://issues.jenkins-ci.org/browse/JENKINS-26128 would allow you to write something along the lines of

def golang = tool name: 'Go 1.2.2', type: 'org.jenkinsci.plugins.golang.GolangInstallation'
withEnv("GOROOT=${golang}", "PATH=${golang}/bin:${env.PATH}") {
  sh 'go build …'
}

which would be just like setting env.WHATEVER except safe for use across multiple slaves in one build.

Second, if the API outlined in https://issues.jenkins-ci.org/browse/JENKINS-26055 were implemented, it would be easier for the Go plugin to offer a Workflow step that would launch go with a selected GolangInstallation.name and arguments, just as a freestyle build step would, including console syntax highlighting and whatever. (The existing SimpleBuildStep API in Jenkins core, used by the Workflow ‘step’ metastep, cannot support long-running external processes that ought to survive Jenkins restarts.)
Reply all
Reply to author
Forward
0 new messages