I have a simple Jenkins pipeline which calls a PS file. The Ps file returns some values and I would like to know if I can save those values onto variables that can be used used within my pipeline steps.
pipeline {
agent {label 'agent'}
stages {
stage("first script"){
steps {
echo "Current agent info: ${env.AGENT_INFO}"
script {
def msg = powershell(returnStdout: true, script: '.\\Get-Guid.ps1')
// def msg = powershell(returnStdout: true, script: 'ipconfig')
println "The new GUID is: ${msg}"
my_guid = msg
env.my_guid = my_guid
// print msg#
echo "Is my GUID: ${my_guid}"
}
}
}
stage("Second Script"){
steps {
script {
def msg = powershell(returnStdout: true, script: 'write-output "Powershell is Great"')
// println msg
}
}
}
}
}
The contents of Get-GUID.ps1 is as follows.
$buildguid = (New-Guid).Guid
$name = "Tom"
Write-Output $buildguid
Write-Output $name
Ideally, I would like to have the value or buildguid stored in a seperate varialbe from the pipeline and name in a seperate variable as well.