Search code examples
powershelljenkinsjenkins-pipeline

How to send value from powershell script to the jenkinsfile


I have to send buildId value from powershell script to the jenkinsfile pipeline. I am trying something like below. Is this right approach?

powershell script

if($out -match "buildId-") {               
           
            $splitline = $out.Split("-")    
           echo "splitline: " $splitline                
            $buildId= $splitline[1]
            echo "buildId: " $buildId
            $buildIds= $env:$buildId.Value              
        }

then want to use that build to pass as a parameter to trigger the build job.

Jenkinsfile

build job: 'build_Test', parameters: [validatingString(name: 'buildId', value: '$buildIds'), string(name: 'TASK', value: 'build')]

Solution

  • You can give it a shot, but I'm not sure simply adding it to an environment variable will allow you to access the value from the Jenkinsfile. You can find more about this problem in this question. However, you maybe able to achieve your goal via the EnvInject plugin, or simply store the value in a file in your workspace and access it via Jenkins later.