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

Powershell not able to get variables when using withCredentials

    Details

    • Similar Issues:

      Description

      When running a step with credentials and powershell, powershell does not retrieve the variables properly, shows as empty / null.  In the same step, using batch function, the variable shows.

      steps {
      withCredentials([string(credentialsId: 'testvar', variable: 'test')])

      { powershell 'echo "This is a $test"' bat 'echo "This is a %test%"'   }

      }

        Attachments

          Activity

          Hide
          stephenconnolly Stephen Connolly added a comment -

          Removing myself as assignee. My current work assignments do not provide sufficient bandwidth to review these issues and in the majority of cases I am only assigned by virtue of being the default assignee. For the credentials-api and scm-api related plugins I have permission to allocate time reviewing changes to these APIs themselves to ensure these APIs remain cohesive, but that can be handled through PR reviews rather than assigning issues in JIRA

          Show
          stephenconnolly Stephen Connolly added a comment - Removing myself as assignee. My current work assignments do not provide sufficient bandwidth to review these issues and in the majority of cases I am only assigned by virtue of being the default assignee. For the credentials-api and scm-api related plugins I have permission to allocate time reviewing changes to these APIs themselves to ensure these APIs remain cohesive, but that can be handled through PR reviews rather than assigning issues in JIRA
          Hide
          duemir Denys Digtiar added a comment -

          powershell step is provided by Pipeline: Nodes and Processes plugin. Updated the components accordingly.

          Show
          duemir Denys Digtiar added a comment - powershell step is provided by Pipeline: Nodes and Processes plugin. Updated the components accordingly.
          Hide
          duemir Denys Digtiar added a comment -

          Hi Tony Nguyen
          The environment variables should be exposed to powershell step the same as to bat or sh. Have you tried using $Env:<variable-name>
          https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-6

          Show
          duemir Denys Digtiar added a comment - Hi Tony Nguyen The environment variables should be exposed to powershell step the same as to bat or sh . Have you tried using $Env:<variable-name> https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-6
          Hide
          tnynyn Tony Nguyen added a comment -

          Hi Denys,

          You're right, I didnt consider it to be an env variable. It worked, thanks.

          Show
          tnynyn Tony Nguyen added a comment - Hi Denys, You're right, I didnt consider it to be an env variable. It worked, thanks.

            People

            • Assignee:
              Unassigned
              Reporter:
              tnynyn Tony Nguyen
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: