Issue
I am using this Powershell plugin for my Jenkins build server. As you can see, one of the recent updates allows for selection of a Powershell version:
The version I have running on my server is 1.7. The problem arises when I try to actually change the version of Powershell, since the example given uses a scripted pipeline, whereas my project uses a declarative one, so the built-in option for version selection is missing. How can I force Jenkins to use Powershell 7.2 instead of the default 5.*?
The only solution I can think of is using Powershell 5 to start Powershell 7 and to then run my .ps1 script like that, but that seems stupid.
Solution
In both declarative and scripted pipeline you can use the pwsh
step to run a script in PS 7.x.
Declarative:
pipeline {
agent any
stages {
stage('Test') {
steps {
pwsh '''
Write-Host "foo"
'''
}
}
}
}
Scripted:
node {
pwsh '''
Write-Host "foo"
'''
}
Answered By - zett42
Answer Checked By - Gilberto Lyons (JavaFixing Admin)