Reputation: 11
I cannot get Jenkins to pass a string Parameter down the pipeline.
When I run the pipeline, I input the string value for $ServiceName
and the job continues but it doesn't pass this param to the first job in the pipe (NEWSERVICE - Add New). In the jenkins file in the 'build' stage I've tried params.ServiceName
, $params.ServiceName
, env.ServiceName
, $env.ServiceName
, $env:ServiceName
. No luck.
I need to pass the param to a Powershell build process in the NEWSERVICE job (which currently just echos the Param with $env:ServiceName
- but it's always empty) Any help would be vastly appreciated.
pipeline {
agent any
parameters{
string(name: 'ServiceName',
defaultValue: '',
description: '',)
}
stages {
stage('Add new Service'){
steps {
build(job: "NEWSERVICE - Add New", parameters: [string(name: 'ServiceName', value: params.ServiceName)])
}
}
}
}
Upvotes: 1
Views: 1878
Reputation: 833
If you are looking to use a Jenkins env var in a powershell script - which i do all the time! - the env var has to be set up as such in Jenkins first. In other words,
env.myVar
in a Jenkins context will be visible as $env:myVar
in a PowerShell context. But you need to set it as an env var, local Jenkins variables won't be visible to a child script (unless passed in as a parameter). I have a detailed writeup here: https://stackoverflow.com/a/62538778/556078
Upvotes: 0
Reputation: 289
In Pipeline you need to pass string parameters like this:
parameters: [
[$class: 'StringParameterValue', name: 'ServiceName', value: ServiceName]
],
Refer this to understand different type of variable passing while calling a job from Jenkinsfile. https://jenkins.io/doc/pipeline/steps/pipeline-build-step/
Upvotes: 1