Mir S Mehdi
Mir S Mehdi

Reputation: 1530

Groovy script with Jenkins for Downstream Parameters

In Jenkins, I am trying to pass parameters into my Downstream jobs for the build pipeline using the Groovy script. In my first job, I have added a Build step "Execute Groovy Script" and added the content into the Groovy Command:

import hudson.model.*
import hudson.util.*
def thr = Thread.currentThread()
def build = thr?.executable
printf "Setting UPSTREAM_ID as "+ build.getEnvVars()['BUILD_ID']  +"\n" ; 
build.addAction(new ParametersAction(new StringParameterValue('UPSTREAM_ID', build.getEnvVars()['BUILD_ID'])))

I get the output:

    [workspace] $ C:\Progra~1\Groovy\Groovy-1.5.8\bin\groovy.exe d:\JenkinsAT\jobs\Test_Job\workspace\hudson8779135058472653024.groovy
    org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, D:\JenkinsAT\jobs\Test_Job\workspace\hudson8779135058472653024.groovy: 6: unable to resolve class ParametersAction 
     @ line 6, column 17.
       build.addAction(new ParametersAction(new StringParameterValue('SVN_UPSTREAM', build.getEnvVars()['BUILD_ID'])))
                       ^
    D:\JenkinsAT\jobs\Test_Job\workspace\hudson8779135058472653024.groovy: 6: unable to resolve class StringParameterValue 
     @ line 6, column 38.
       build.addAction(new ParametersAction(new StringParameterValue('SVN_UPSTREAM', build.getEnvVars()['BUILD_ID'])))
                                            ^

2 errors

I have installed Groovy 1.5.8 on my machine and my Jenkins Version is 1.519. What wrong I am doing here.

Upvotes: 1

Views: 5487

Answers (1)

Mir S Mehdi
Mir S Mehdi

Reputation: 1530

Got this fixed by placing the Jenkins-core.jar into the groovy lib directory and changing the Build type to Execute system Groovy Script

Upvotes: 7

Related Questions