Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins pipeline boolean parameter evaluation

I've a Jenkins pipeline that should evaluate a boolean parameter called saveEar:

stage ('Publish to CIFS'){
  echo String.valueOf(saveEar)
  if ( saveEar ) {
    cifsPublisher alwaysPublishFromMaster: false, continueOnError: false, failOnError: false, publishers: [[
      configName: 'MY-CONFIG', transfers: [[
        cleanRemote: false, 
        excludes: '', 
        flatten: false, 
        makeEmptyDirs: false, 
        noDefaultExcludes: false, 
        patternSeparator: '[, ]+', 
        remoteDirectory: "jenkins-job_" + '$JOB_NAME' + '$BUILD_NUMBER', 
        remoteDirectorySDF: false, 
        removePrefix: 'build/libs', 
        sourceFiles: 'build/libs/my.ear']], 
      usePromotionTimestamp: false, 
      useWorkspaceInPromotion: false, 
      verbose: true
    ]]
  }
}

This is the parameter configuration:

    <hudson.model.BooleanParameterDefinition>
      <name>saveEar</name>
      <description>valore per scegliere se salvare l&apos;EAR generato su XXXX (true =&gt; salva, default false)</description>
      <defaultValue>false</defaultValue>
    </hudson.model.BooleanParameterDefinition>

I'm expecting that when saveEar is false Jenkins will not publish over CIFS but it isn't.

This is the pipeline log:

[Pipeline] stage
[Pipeline] { (Publish to CIFS)
[Pipeline] echo
false
[Pipeline] cifsPublisher
CIFS: Connecting from host [jenkins.mydomain]
CIFS: Connecting with configuration [MY-CONFIG] ...
CIFS: Removing WINS from name resolution
CIFS: Setting response timeout [30.000]
CIFS: Setting socket timeout [35.000]
<...>
CIFS: Transferred 1 file(s)
[Pipeline] }

Can anyone help clarify this issue please?

like image 689
sgargel Avatar asked Feb 06 '18 15:02

sgargel


1 Answers

To access a parameter within pipeline stages, use params.variableName. In your case, you should use params.saveEar to access the value.

like image 120
dot Avatar answered Oct 12 '22 13:10

dot