Modify parent build parameters or global environment variable in a MultiJob project - Groovy

182 views
Skip to first unread message

geek876

unread,
Oct 15, 2015, 6:16:57 AM10/15/15
to Jenkins Users
Hello,

I was wondering how should I achieve the below. Tried few things but not getting anywhere

Scene:
I have a parameterized multijob project with parameter 'X=yes' and two multijob phases (a and b).
I want that when 'a' runs, it should modify parameter 'X' of parent and set it to 'X=no' after checking a condition. Then I only run b if 'X=yes' (i.e use enable-condition within multijob phase and run it only if X=yes). 
I don't want to do any logic within the parent Multijob (no SCM checkout etc or any inline script). I am able to modify the parameter within phase a but it does'nt seem to set the parent parameter value. Or in other words, when b starts, it still sees the parameter as set by the parent multijob and not as changed by a.

I am using the following groovy script within multjob phase a.

def parameters = new ArrayList<StringParameterValue>()
addParameter(parameters, 'X', 'no' )
addNewParamsToBuild(parameters)

private boolean addParameter(ArrayList<StringParameterValue> pl, String key, value) {
    pl.add(new StringParameterValue(key, value))
}

private void addNewParamsToBuild(ArrayList<StringParameterValue> parameters) {
    def newParams
    def oldParams = build.getAction(ParametersAction.class)

    if (oldParams != null) {
        newParams = oldParams.createUpdated(parameters)
        build.actions.remove(oldParams)
    } else {
        newParams = new ParametersAction(parameters)
    }

    build.addAction(newParams)
}

I also tried this https://themettlemonkey.wordpress.com/tag/jenkins/ in multijob phase a but it seems to only set it within a and not the parent value so that b can have it.

I am open to use environment varilables too so if there is any way of 'multijob phase a' setting or changing the global environment varilable that 'multijob phase b' can see then that should do too. 

Any help in the direction would really be appreciated.

Reply all
Reply to author
Forward
0 new messages