Jenkins Pipeline Access stage steps variable in power shell execution
It isn't probably the most elegant way to do it but I've done it like this:(I will use your same example)
stages { stage ('sometask') { steps{ script { def someString = 'Hi' withCredentials(...) { def out = powershell(returnStdout: true, script: ''' PowerShellCommands.... Write-Host ''' + someString + ''' someMorePowerShellCommands ''') println out } }
So basically what I'm doing is concatenating the value of
someString
In the middle of the script, if you would for instance need to pass more variables you need to follow the same logic:
''' some script code ''' + variableName + ''' some more script code''' + anotherVariableName + ''' evenMoreScriptCode '''
In my case I am using config parameters and instead of the
variableName
I am using
config.webURL
for instance.
Hope this helps.
EN
Following should work :)
stages {
stage ('sometask') { steps{ script { def someString = 'Hi' withCredentials(...) { def out = powershell(returnStdout: true, script: """ // Accessing someString Write-Host $someString """) println out } } }
}