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

Powershell execution within GIT Multibranch pipeline failing

    Details

    • Similar Issues:

      Description

      I have been using Jenkins GIT Multibranch for a few weeks now.  Today I upgraded to 2.89.4 and consequently my existing job started failing on the powershell execution:
      Started by user
      Mike Henderson
      > C:\Program Files\Git\bin\git.exe rev-parse --is-inside-work-tree # timeout=10
      Setting origin to
      https://pbsorters.visualstudio.com/Sorter%20Projects/Sorter%20Projects%20Team/_git/Software_C_Sharp
      > C:\Program Files\Git\bin\git.exe config remote.origin.url
      https://pbsorters.visualstudio.com/Sorter%20Projects/Sorter%20Projects%20Team/_git/Software_C_Sharp

      1. timeout=10
        Fetching origin...
        Fetching upstream changes from origin
        > C:\Program Files\Git\bin\git.exe --version # timeout=10
        using GIT_ASKPASS to set credentials Jenkins Feb-2018
        > C:\Program Files\Git\bin\git.exe fetch --tags --progress origin +refs/heads/:refs/remotes/origin/
        Seen branch in repository origin/Release1.5
        Seen branch in repository origin/Task11982
        Seen branch in repository origin/TestJenkinsFile
        Seen branch in repository origin/sqa1.5
        Seen 4 remote branches
        Obtained Jenkinsfile from 55e5fb519d6276a4b566d6dfdf5de88e395cc125
        Running in Durability level: MAX_SURVIVABILITY
        [Pipeline] node
        Running on
        Node 1
        in D:\Jenkins\workspace\rp_-_CS_GIT_TestJenkinsFile-CYLWMI6AWK3EFHJP3GSCB3TL4W5QCOFFI2SCUTRUEZAATYAY2G3Q
        [Pipeline] {
        [Pipeline] echo
        Sanity Check 1
        [Pipeline] powershell
        [rp_-_CS_GIT_TestJenkinsFile-CYLWMI6AWK3EFHJP3GSCB3TL4W5QCOFFI2SCUTRUEZAATYAY2G3Q] Running PowerShell script
        D:\Jenkins\workspace\rp_-_CS_GIT_TestJenkinsFile-CYLWMI6AWK3EFHJP3GSCB3TL4W5QCOFFI2SCUTRUEZAATYAY2G3Q@tmp\durable-311bd602\powershellWrapper.ps1 : The term 'powershell' is not recognized as
        the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
        At D:\Jenkins\workspace\rp_-_CS_GIT_TestJenkinsFile-CYLWMI6AWK3EFHJP3GSCB3TL4W5QCOFFI2SCUTRUEZAATYAY2G3Q@tmp\durable-311bd602\powershellHelper.ps1:53 char:9
        + & { & $MainScript | Out-FileNoBom -Writer $OutputWriter } *>&1 | ...
        + ~~~~~~~~~~~~~
        + CategoryInfo : ObjectNotFound: (powershell:String) [powershellW rapper.ps1], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException,powershellWrapper.ps1

      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      ERROR: script returned exit code 1
      Finished: FAILURE
      I downgraded back to 2.89.3 but the problem persists. 

      I logged into the node where this is executing and opened powershell and ran an example of this powershellWrapper.ps1 and it executed fine.  In the folder that is called about above though, there is no folders or scripts.  Not sure if it cleans it out or not automatically.  The powershell plugin hasn't changed in some time, so I think it is how the wrapper is generated could be the issue, but since the file is gone I can't even verify what was in it.  I found an existing script in another job folder that was run yesterday successful.

       

      Here is the contents of the jenkinsfile that produced the above output:

      node('("Node 1")||("Node 2")') {
      echo 'Sanity Check 1'
      powershell 'Write-Output "Sanity Check 2"'
      echo 'Sanity Check 3'

      }

       

        Attachments

          Activity

          Hide
          gabloe Gabriel Loewen added a comment -

          That's not surprising, since the powershell plugin for freestyle jobs and in pipeline are not related 

          Just to be clear, if you execute "powershell" without a .exe extension from a powershell prompt it fails? If this is the case then I can submit a small PR to always call powershell with extension Sam Van Oort.  The reason that I did this was to avoid having separate code paths for windows powershell and open powershell since executing "powershell" without the added .exe extension worked fine on all versions of windows in my testing, and there is no concept of file extension in *nix platforms.

          Show
          gabloe Gabriel Loewen added a comment - That's not surprising, since the powershell plugin for freestyle jobs and in pipeline are not related  Just to be clear, if you execute "powershell" without a .exe extension from a powershell prompt it fails? If this is the case then I can submit a small PR to always call powershell with extension Sam Van Oort .  The reason that I did this was to avoid having separate code paths for windows powershell and open powershell since executing "powershell" without the added .exe extension worked fine on all versions of windows in my testing, and there is no concept of file extension in *nix platforms.
          Hide
          mikehend Mike Henderson added a comment -

           

          Works both ways for me, with and without the extension.

          I did this on the Windows 2008 R2 box which then makes me think it is some kind of path issue when run from within the pipeline.

          Show
          mikehend Mike Henderson added a comment -   Works both ways for me, with and without the extension. I did this on the Windows 2008 R2 box which then makes me think it is some kind of path issue when run from within the pipeline.
          Hide
          gabloe Gabriel Loewen added a comment -

          Oh!  That changes my prior assumption then. I do not know what kind of path issues we would hit in pipeline because there is no difference with how we execute powershell in pipeline from how it is executed in the powershell freestyle plugin except that in pipeline we add the -NoProfile command line argument as a security and performance measure to prevent powershell from automatically executing profile scripts.  But, it's not even getting to that point...  I'll have to investigate this further to understand what is happening here.

          Show
          gabloe Gabriel Loewen added a comment - Oh!  That changes my prior assumption then. I do not know what kind of path issues we would hit in pipeline because there is no difference with how we execute powershell in pipeline from how it is executed in the powershell freestyle plugin except that in pipeline we add the -NoProfile command line argument as a security and performance measure to prevent powershell from automatically executing profile scripts.  But, it's not even getting to that point...  I'll have to investigate this further to understand what is happening here.
          Hide
          mikehend Mike Henderson added a comment -

          Thanks for looking at this! 

          Show
          mikehend Mike Henderson added a comment - Thanks for looking at this! 
          Hide
          iamrewt Ryan Taylor added a comment - - edited

          Has there been any traction on this? I am experiencing a similar issue.

          • Windows 2012 R2
          • Jenkins v2.141
          • Pipeline 2.5
            • Pipeline Graph Analysis Plugin 1.7
            • Pipeline: API 2.29
            • Pipeline: Basic Steps 2.10
            • Pipeline: Build Step 2.7
            • Pipeline: Declarative 1.3.2
            • Pipeline: Declarative Agent API 1.1.1
            • Pipeline: Declarative Extension Points API 1.3.2
            • Pipeline: Groovy 2.54
            • Pipeline: Input Step 2.8
            • Pipeline: Job 2.24
            • Pipeline: Milestone Step 1.3.1
            • Pipeline: Model API 1.3.2
            • Pipeline: Multibranch 2.20
            • Pipeline: Nodes and Processes 2.21
            • Pipeline: REST API Plugin 2.10
            • Pipeline: SCM Step 2.6
            • Pipeline: Shared Groovy Libraries 2.10
            • Pipeline: Stage Step 2.3
            • Pipeline: Stage Tags Metadata 1.3.2
            • Pipeline: Stage View Plugin 2.10
            • Pipeline: Step API 2.16
            • Pipeline: Supporting APIs 2.20

          I did not have this issue before I upgraded Jenkins and Pipelines. Previously Jenkins was at v2.75. Pipelines plugins were generally a patch release behind. I am not sure which specific upgrade caused the issue.

          I had more time to investigate and apparently this was due to our Jenkins instance having the PATH variable overridden. The overridden PATH did not include the path to PowerShell. When I added `C:\WINDOWS\System32\WindowsPowerShell\v1.0\` to the PATH my issue was resolved.

          Show
          iamrewt Ryan Taylor added a comment - - edited Has there been any traction on this? I am experiencing a similar issue. Windows 2012 R2 Jenkins v2.141 Pipeline 2.5 Pipeline Graph Analysis Plugin 1.7 Pipeline: API 2.29 Pipeline: Basic Steps 2.10 Pipeline: Build Step 2.7 Pipeline: Declarative 1.3.2 Pipeline: Declarative Agent API 1.1.1 Pipeline: Declarative Extension Points API 1.3.2 Pipeline: Groovy 2.54 Pipeline: Input Step 2.8 Pipeline: Job 2.24 Pipeline: Milestone Step 1.3.1 Pipeline: Model API 1.3.2 Pipeline: Multibranch 2.20 Pipeline: Nodes and Processes 2.21 Pipeline: REST API Plugin 2.10 Pipeline: SCM Step 2.6 Pipeline: Shared Groovy Libraries 2.10 Pipeline: Stage Step 2.3 Pipeline: Stage Tags Metadata 1.3.2 Pipeline: Stage View Plugin 2.10 Pipeline: Step API 2.16 Pipeline: Supporting APIs 2.20 I did not have this issue before I upgraded Jenkins and Pipelines. Previously Jenkins was at v2.75. Pipelines plugins were generally a patch release behind. I am not sure which specific upgrade caused the issue. I had more time to investigate and apparently this was due to our Jenkins instance having the PATH variable overridden. The overridden PATH did not include the path to PowerShell. When I added `C:\WINDOWS\System32\WindowsPowerShell\v1.0\` to the PATH my issue was resolved.

            People

            • Assignee:
              gabloe Gabriel Loewen
              Reporter:
              mikehend Mike Henderson
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: