Using Jenkins 2.8.

How/where do i define the parameter?

1) For regular build jobs
Tried: Prepare an environment for the run -> Properties Content 
-> UPSTREAM_TRIGGERED=false
Did not work. The value if always false, even if ProjectA sends the value 
with true.

2) For pipeline jobs
Tried: withEnv(["UPSTREAM_TRIGGERED=true"]) {
Did not work

tirsdag 7. juni 2016 12.34.38 UTC+2 skrev Antonio Muñiz følgende:
>
> If you are using Jenkins 1.651.2 (or 2.3+) you are hitting the 
> SECURITY-170 fix: undeclared parameters are ignored (and not injected 
> as env vars). 
> You have to define the parameter (`UPSTREAM_TRIGGERED`) in the downstream 
> build. 
>
> On Tue, Jun 7, 2016 at 9:39 AM, Sverre Moe <sverr...@gmail.com 
> <javascript:>> wrote: 
> > I am trying to pass a parameter to a scheduled build, but the build does 
> not 
> > get the parameter. 
> > 
> > When ProjectA schedule a build of ProjectB it should pass along a 
> parameter 
> > I called UPSTREAM_TRIGGERED. 
> > When ProjectB starts building there are no parameters passed in from 
> > ProjectA. 
> > 
> > I have the following Groovy Postbuild script running. 
> > #!/usr/bin/env groovy 
> > 
> > import jenkins.model.Jenkins 
> > import hudson.matrix.MatrixProject 
> > import hudson.matrix.MatrixBuild; 
> > import hudson.matrix.MatrixRun; 
> > import hudson.console.ModelHyperlinkNote 
> > import hudson.model.Action 
> > import hudson.model.Cause 
> > import hudson.model.ParametersAction 
> > import hudson.model.ParametersDefinitionProperty 
> > import hudson.model.BooleanParameterValue 
> > import hudson.model.Cause.UpstreamCause 
> > import hudson.model.queue.QueueTaskFuture 
> > import hudson.model.Result 
> > 
> > if (manager.buildIsA(MatrixBuild.class)) { 
> >     final def build = manager.build 
> >     final def buildProject = build.getParent() 
> > 
> >     def upstreamTrigger = false 
> >     def upstreamTriggerValue = manager.envVars['UPSTREAM_TRIGGERED'] 
> >     if (upstreamTriggerValue != null && !upstreamTriggerValue.isEmpty()) 
> { 
> >         upstreamTrigger = Boolean.parseBoolean(upstreamTriggerValue) 
> >     } 
> > 
> >     if (upstreamTrigger) { 
> >         return 
> >     } 
> > 
> >     final def downstreamProjects = 
> manager.envVars['DOWNSTREAM_PROJECTS'] 
> >     if (downstreamProjects != null) { 
> >         final def downstreamProjectsList = downstreamProjects.split(", 
> > ").toList() 
> > 
> >         final def preliminaryResult = build.getResult() 
> >         if (preliminaryResult.isBetterOrEqualTo(Result.SUCCESS)) { 
> >             downstreamProjectsList.each { projectName -> 
> >                 def project = 
> > Jenkins.instance.getItemByFullName(projectName) 
> >                 if (project == null) { 
> >                     manager.listener.logger.println("Cannot schedule 
> build. 
> > Poject " + projectName + " does not exist") 
> >                     return 
> >                 } 
> > 
> >                 if (project.isDisabled()) { 
> >                     manager.listener.logger.println("Project " + 
> > ModelHyperlinkNote.encodeTo(project) + " disabled. Skipping build") 
> >                     return 
> >                 } 
> > 
> >                 def params = [] 
> >                 def extraParameterValue = new 
> > BooleanParameterValue('UPSTREAM_TRIGGERED', true) 
> >                 params.add(extraParameterValue) 
> > 
> >                 /* Add the project's default parameters */ 
> >                 def parametersDefProp = 
> > project.getProperty(ParametersDefinitionProperty.class) 
> >                 parametersDefProp.getParameterDefinitions().each { param 
> -> 
> >                     def parameterValue = 
> param.getDefaultParameterValue() 
> >                     params.add(parameterValue) 
> >                 } 
> > 
> >                 def parametersAction = new ParametersAction(params) 
> > 
> >                 def cause = new UpstreamCause(build) 
> >                 manager.listener.logger.println("Schedule job " + 
> > ModelHyperlinkNote.encodeTo(project)) 
> >                 def futureTask = 
> project.scheduleBuild2(project.quietPeriod, 
> > cause, parametersAction) 
> > 
> >                 if (futureTask == null) { 
> >                     manager.listener.logger.println("Unable to schedule 
> job 
> > for " + ModelHyperlinkNote.encodeTo(project)) 
> >                     manager.buildUnstable() 
> >                     return 
> >                 } 
> > 
> >                 MatrixBuild startedBuild = futureTask.waitForStart(); 
> >                 if (startedBuild == null) { 
> >                     manager.listener.logger.println("Failed to start " + 
> > ModelHyperlinkNote.encodeTo(project)) 
> >                     manager.buildUnstable() 
> >                     return 
> >                 } 
> > 
> >                 manager.listener.logger.println("Build " + 
> > ModelHyperlinkNote.encodeTo('/'+ startedBuild.getUrl(), 
> > startedBuild.getFullDisplayName()) + " started") 
> >                 MatrixBuild finishedBuild = futureTask.get() 
> >                 def finishedBuildResult = finishedBuild.getResult() 
> > 
> > 
> > manager.listener.logger.println(ModelHyperlinkNote.encodeTo('/'+ 
> > finishedBuild.getUrl(), 
> >                         finishedBuild.getFullDisplayName()) + " 
> completed 
> > with result " + finishedBuildResult) 
> > 
> >                 if (finishedBuildResult.isWorseThan(Result.SUCCESS)) { 
> >                     manager.buildUnstable() 
> >                 } 
> >             } 
> >         } 
> >     } else { 
> >         manager.listener.logger.println("No downstream projects to 
> trigger") 
> >     } 
> > } 
> > 
> > I included the complete script for measure. I believe the problem lies 
> with 
> > this code snippet in the script 
> > def params = [] 
> > def extraParameterValue = new 
> BooleanParameterValue('UPSTREAM_TRIGGERED', 
> > true) 
> > params.add(extraParameterValue) 
> > 
> > /* Add the project's default parameters */ 
> > def parametersDefProp = 
> > project.getProperty(ParametersDefinitionProperty.class) 
> > parametersDefProp.getParameterDefinitions().each { param -> 
> >     def parameterValue = param.getDefaultParameterValue() 
> >     params.add(parameterValue) 
> > } 
> > 
> > def parametersAction = new ParametersAction(params) 
> > 
> > def cause = new UpstreamCause(build) 
> > manager.listener.logger.println("Schedule job " + 
> > ModelHyperlinkNote.encodeTo(project)) 
> > def futureTask = project.scheduleBuild2(project.quietPeriod, cause, 
> > parametersAction) 
> > 
> > The parameter I try to read from environment variables are always 
> "false" 
> >     def upstreamTriggerValue = manager.envVars['UPSTREAM_TRIGGERED'] 
> >     manager.listener.logger.println "upstreamTriggerValue=" + 
> > upstreamTriggerValue 
> > This prints out upstreamTriggerValue=false 
> > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Jenkins Developers" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to jenkinsci-de...@googlegroups.com <javascript:>. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/jenkinsci-dev/34b95aef-25d1-4030-af1d-6bf28e487e81%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
> -- 
> Antonio Muñiz 
> Software Engineer 
> CloudBees, Inc. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/894a77b7-c09f-4576-b517-5eed915767a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to