Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-46379

withEnv mess with Job parameter (not case sensitive)

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Trivial Trivial
    • pipeline
    • None

      This is probably more a miss usage than an issue. In that case, would you please add some precisions on the basic-steps documentation?

       

      Description of the issue:

      I have a simple pipeline with the string parameter "ENVNAME". A call to

      def var = 'foo'
      withEnv(["envname=${var}"]) {
          sh 'echo $envname'
      }

      results in an empty string even with the parameter variable ENVNAME defined (but I am not looking for this variable here) I would have not expected variable name clash here. Would you?

      Moreover, the implementation is under a jenkins library, there is no clever way to avoid collision (but to check env.ENVNAME before) that comes to my mind.

      Of course, changing the string "envname" to whatever else works as intended.

       

       

          [JENKINS-46379] withEnv mess with Job parameter (not case sensitive)

          Kevin Raymond created issue -

          Andrew Bayer added a comment -

          I'm confused. Are you saying that "envname=whatever" doesn't take effect if ENVNAME is already defined?

          Andrew Bayer added a comment - I'm confused. Are you saying that "envname=whatever" doesn't take effect if ENVNAME is already defined?

          Kevin Raymond added a comment -

          Yes exactly.

          Let's take a full example. I have a simple pipeline with only one string parameter "ENVNAME" which default value is "foo".

          Here is the pipeline code:

          stage('test'){
              def var = 'bar'
          
              node{
                  echo env.ENVNAME
                  //   foo
          
                  withEnv(["envname=${var}"]) {
                      sh 'echo "envname is: $envname while ENVNAME is: $ENVNAME"'
                      //        envname is:  while ENVNAME is: bar
                  }
                  
                  withEnv(["name=${var}"]) {
                      sh 'echo "name is: $name while ENVNAME is: $ENVNAME"'
                      //        name is: bar while ENVNAME is: foo
                  }
              }
          }
          

          And the output is following:

          [Pipeline] stage
          [Pipeline] { (test)
          [Pipeline] node
          Running on localhost in /home/slave/j2data/workspace/dummy-pipeline
          [Pipeline] {
          [Pipeline] echo
          foo
          [Pipeline] withEnv
          [Pipeline] {
          [Pipeline] sh
          [dummy-pipeline] Running shell script
          + echo 'envname is:  while ENVNAME is: bar'
          envname is:  while ENVNAME is: bar
          [Pipeline] }
          [Pipeline] // withEnv
          [Pipeline] withEnv
          [Pipeline] {
          [Pipeline] sh
          [dummy-pipeline] Running shell script
          + echo 'name is: bar while ENVNAME is: foo'
          name is: bar while ENVNAME is: foo
          [Pipeline] }
          [Pipeline] // withEnv
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] End of Pipeline
          Finished: SUCCESS

          I would think the first withEnv block would print the variable. Either the redefined one or the job parameter. Instead, it just drops the value without being case sensitive.

          Kevin Raymond added a comment - Yes exactly. Let's take a full example. I have a simple pipeline with only one string parameter "ENVNAME" which default value is "foo". Here is the pipeline code: stage( 'test' ){ def var = 'bar' node{ echo env.ENVNAME // foo withEnv([ "envname=${ var }" ]) { sh 'echo "envname is: $envname while ENVNAME is: $ENVNAME" ' // envname is:   while ENVNAME is: bar } withEnv([ "name=${ var }" ]) { sh 'echo "name is: $name while ENVNAME is: $ENVNAME" ' // name is: bar while ENVNAME is: foo } } } And the output is following: [Pipeline] stage [Pipeline] { (test) [Pipeline] node Running on localhost in /home/slave/j2data/workspace/dummy-pipeline [Pipeline] { [Pipeline] echo foo [Pipeline] withEnv [Pipeline] { [Pipeline] sh [dummy-pipeline] Running shell script + echo 'envname is: while ENVNAME is: bar' envname is: while ENVNAME is: bar [Pipeline] } [Pipeline] // withEnv [Pipeline] withEnv [Pipeline] { [Pipeline] sh [dummy-pipeline] Running shell script + echo 'name is: bar while ENVNAME is: foo' name is: bar while ENVNAME is: foo [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] } [Pipeline] // stage [Pipeline] End of Pipeline Finished: SUCCESS I would think the first withEnv block would print the variable. Either the redefined one or the job parameter. Instead, it just drops the value without being case sensitive.

          Rick added a comment - - edited

          Can you give your plugin versioin? Because it'is all right. My plugin version like bleow:
          Pipeline: Basic Steps 2.6

          shaiton

          Rick added a comment - - edited Can you give your plugin versioin? Because it'is all right. My plugin version like bleow: Pipeline: Basic Steps 2.6 shaiton
          Rick made changes -
          Assignee New: Rick [ surenpi ]

          Kevin Raymond added a comment -

          I am also using Basic Steps 2.6 under Jenkins ver. 2.73.3

          I have just reproduced this issue. How can I give you more input?

          Kevin Raymond added a comment - I am also using Basic Steps 2.6 under Jenkins ver. 2.73.3 I have just reproduced this issue. How can I give you more input?

          Rick added a comment -

          You just use the case that your last post? I can retry it.
          shaiton

          Rick added a comment - You just use the case that your last post? I can retry it. shaiton
          Kevin Raymond made changes -
          Attachment New: config.xml [ 41769 ]

          Kevin Raymond added a comment -

          yes surenpi the one I posted as a comment-311533.

          Have you defined a String parameter spelled 'ENVNAME' in your pipeline?
          I am adding the config.xml job definition. config.xml

          Kevin Raymond added a comment - yes surenpi the one I posted as a comment-311533 . Have you defined a String parameter spelled 'ENVNAME' in your pipeline? I am adding the config.xml job definition. config.xml

          This drove me utterly insane working on my pipeline until I figured out what was symptomatically going on and came across this bug. Is there anything I can do to help move forwards addressing this issue?

          Matthew Gabeler-Lee added a comment - This drove me utterly insane working on my pipeline until I figured out what was symptomatically going on and came across this bug. Is there anything I can do to help move forwards addressing this issue?

            surenpi Rick
            shaiton Kevin Raymond
            Votes:
            4 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: