Is it possible to propagate variable from a Jenkins pipeline job script to loaded jenkinsfile script?
up vote
0
down vote
favorite
I would like to know if it's possible to pass a variable define in a jenkins pipeline job to a loaded script like.
The loaded script
Pipeline Job
node
// Some declaration and code
stage('Prepare deploy')
// Create a talbe for the servers lists
def servers = [:]
// For each server know, if deployment is enabled
// deploy resources
params.each srv, value ->
if ("$value" == "true")
// add the current current to the enabled servers
servers["Server $srv"] =
// Define specific variable
String SERVER=props."SRV_$srv"
String CONF=env.DEPLOY_HOME + "/$srv"
// Install server - the SERVER and CONF variable need to be propagate to the others scripts
load env.JENKINSFILES_DIRECTORY + "/server-configuration"
load env.JENKINSFILES_DIRECTORY + "/server-deploiement"
load env.JENKINSFILES_DIRECTORY + "/server-postconfig"
load env.JENKINSFILES_DIRECTORY + "/server-start"
parallel servers
server-configuration file
#!/usr/bin/env groovy
node
// Some declaration
stage('configure serveur')
// The variable SERVER and CONF must be visible here
// is it possible ?
sh "ssh -X " + env.USER +"@$SERVER 'sh echo "$CONF"'"
Thanks
jenkins groovy jenkins-pipeline
add a comment |
up vote
0
down vote
favorite
I would like to know if it's possible to pass a variable define in a jenkins pipeline job to a loaded script like.
The loaded script
Pipeline Job
node
// Some declaration and code
stage('Prepare deploy')
// Create a talbe for the servers lists
def servers = [:]
// For each server know, if deployment is enabled
// deploy resources
params.each srv, value ->
if ("$value" == "true")
// add the current current to the enabled servers
servers["Server $srv"] =
// Define specific variable
String SERVER=props."SRV_$srv"
String CONF=env.DEPLOY_HOME + "/$srv"
// Install server - the SERVER and CONF variable need to be propagate to the others scripts
load env.JENKINSFILES_DIRECTORY + "/server-configuration"
load env.JENKINSFILES_DIRECTORY + "/server-deploiement"
load env.JENKINSFILES_DIRECTORY + "/server-postconfig"
load env.JENKINSFILES_DIRECTORY + "/server-start"
parallel servers
server-configuration file
#!/usr/bin/env groovy
node
// Some declaration
stage('configure serveur')
// The variable SERVER and CONF must be visible here
// is it possible ?
sh "ssh -X " + env.USER +"@$SERVER 'sh echo "$CONF"'"
Thanks
jenkins groovy jenkins-pipeline
1
I got another hint on your script: since the loaded scripts have their own node block the parallel call should not be done inside a node block as this will only block a node for no reason. If the runtime is a few secs only this won’t hurt. However if there’s a shortage in nodes you may block one node until another one will be free... Just saying:)
– Joerg S
Nov 11 at 7:16
Hum... Thanks. If I understand what you said, it's better if I do that ? def server .... node .... parralel server ? (parralel call is inside the node ?) Or I suppress the node block in the loaded script ?
– Sylvain Goubaud
Nov 12 at 18:55
This will depend on your need. If you'll be able to reuse that node I'd rather prefer it that way as - for large Jenkins instances - opening a new node block may take up to some minutes.
– Joerg S
Nov 13 at 17:08
Thanks for your answer. I made some tries. So, for my needs, It's better is I delete the node block in server-configuration file. Thanks
– Sylvain Goubaud
Nov 14 at 20:24
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I would like to know if it's possible to pass a variable define in a jenkins pipeline job to a loaded script like.
The loaded script
Pipeline Job
node
// Some declaration and code
stage('Prepare deploy')
// Create a talbe for the servers lists
def servers = [:]
// For each server know, if deployment is enabled
// deploy resources
params.each srv, value ->
if ("$value" == "true")
// add the current current to the enabled servers
servers["Server $srv"] =
// Define specific variable
String SERVER=props."SRV_$srv"
String CONF=env.DEPLOY_HOME + "/$srv"
// Install server - the SERVER and CONF variable need to be propagate to the others scripts
load env.JENKINSFILES_DIRECTORY + "/server-configuration"
load env.JENKINSFILES_DIRECTORY + "/server-deploiement"
load env.JENKINSFILES_DIRECTORY + "/server-postconfig"
load env.JENKINSFILES_DIRECTORY + "/server-start"
parallel servers
server-configuration file
#!/usr/bin/env groovy
node
// Some declaration
stage('configure serveur')
// The variable SERVER and CONF must be visible here
// is it possible ?
sh "ssh -X " + env.USER +"@$SERVER 'sh echo "$CONF"'"
Thanks
jenkins groovy jenkins-pipeline
I would like to know if it's possible to pass a variable define in a jenkins pipeline job to a loaded script like.
The loaded script
Pipeline Job
node
// Some declaration and code
stage('Prepare deploy')
// Create a talbe for the servers lists
def servers = [:]
// For each server know, if deployment is enabled
// deploy resources
params.each srv, value ->
if ("$value" == "true")
// add the current current to the enabled servers
servers["Server $srv"] =
// Define specific variable
String SERVER=props."SRV_$srv"
String CONF=env.DEPLOY_HOME + "/$srv"
// Install server - the SERVER and CONF variable need to be propagate to the others scripts
load env.JENKINSFILES_DIRECTORY + "/server-configuration"
load env.JENKINSFILES_DIRECTORY + "/server-deploiement"
load env.JENKINSFILES_DIRECTORY + "/server-postconfig"
load env.JENKINSFILES_DIRECTORY + "/server-start"
parallel servers
server-configuration file
#!/usr/bin/env groovy
node
// Some declaration
stage('configure serveur')
// The variable SERVER and CONF must be visible here
// is it possible ?
sh "ssh -X " + env.USER +"@$SERVER 'sh echo "$CONF"'"
Thanks
jenkins groovy jenkins-pipeline
jenkins groovy jenkins-pipeline
asked Nov 10 at 16:44
Sylvain Goubaud
485
485
1
I got another hint on your script: since the loaded scripts have their own node block the parallel call should not be done inside a node block as this will only block a node for no reason. If the runtime is a few secs only this won’t hurt. However if there’s a shortage in nodes you may block one node until another one will be free... Just saying:)
– Joerg S
Nov 11 at 7:16
Hum... Thanks. If I understand what you said, it's better if I do that ? def server .... node .... parralel server ? (parralel call is inside the node ?) Or I suppress the node block in the loaded script ?
– Sylvain Goubaud
Nov 12 at 18:55
This will depend on your need. If you'll be able to reuse that node I'd rather prefer it that way as - for large Jenkins instances - opening a new node block may take up to some minutes.
– Joerg S
Nov 13 at 17:08
Thanks for your answer. I made some tries. So, for my needs, It's better is I delete the node block in server-configuration file. Thanks
– Sylvain Goubaud
Nov 14 at 20:24
add a comment |
1
I got another hint on your script: since the loaded scripts have their own node block the parallel call should not be done inside a node block as this will only block a node for no reason. If the runtime is a few secs only this won’t hurt. However if there’s a shortage in nodes you may block one node until another one will be free... Just saying:)
– Joerg S
Nov 11 at 7:16
Hum... Thanks. If I understand what you said, it's better if I do that ? def server .... node .... parralel server ? (parralel call is inside the node ?) Or I suppress the node block in the loaded script ?
– Sylvain Goubaud
Nov 12 at 18:55
This will depend on your need. If you'll be able to reuse that node I'd rather prefer it that way as - for large Jenkins instances - opening a new node block may take up to some minutes.
– Joerg S
Nov 13 at 17:08
Thanks for your answer. I made some tries. So, for my needs, It's better is I delete the node block in server-configuration file. Thanks
– Sylvain Goubaud
Nov 14 at 20:24
1
1
I got another hint on your script: since the loaded scripts have their own node block the parallel call should not be done inside a node block as this will only block a node for no reason. If the runtime is a few secs only this won’t hurt. However if there’s a shortage in nodes you may block one node until another one will be free... Just saying:)
– Joerg S
Nov 11 at 7:16
I got another hint on your script: since the loaded scripts have their own node block the parallel call should not be done inside a node block as this will only block a node for no reason. If the runtime is a few secs only this won’t hurt. However if there’s a shortage in nodes you may block one node until another one will be free... Just saying:)
– Joerg S
Nov 11 at 7:16
Hum... Thanks. If I understand what you said, it's better if I do that ? def server .... node .... parralel server ? (parralel call is inside the node ?) Or I suppress the node block in the loaded script ?
– Sylvain Goubaud
Nov 12 at 18:55
Hum... Thanks. If I understand what you said, it's better if I do that ? def server .... node .... parralel server ? (parralel call is inside the node ?) Or I suppress the node block in the loaded script ?
– Sylvain Goubaud
Nov 12 at 18:55
This will depend on your need. If you'll be able to reuse that node I'd rather prefer it that way as - for large Jenkins instances - opening a new node block may take up to some minutes.
– Joerg S
Nov 13 at 17:08
This will depend on your need. If you'll be able to reuse that node I'd rather prefer it that way as - for large Jenkins instances - opening a new node block may take up to some minutes.
– Joerg S
Nov 13 at 17:08
Thanks for your answer. I made some tries. So, for my needs, It's better is I delete the node block in server-configuration file. Thanks
– Sylvain Goubaud
Nov 14 at 20:24
Thanks for your answer. I made some tries. So, for my needs, It's better is I delete the node block in server-configuration file. Thanks
– Sylvain Goubaud
Nov 14 at 20:24
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
withEnv
is what you are looking for
node
// Some declaration and code
stage('Prepare deploy')
// Create a talbe for the servers lists
def servers = [:]
// For each server know, if deployment is enabled
// deploy resources
params.each srv, value ->
if ("$value" == "true")
// add the current current to the enabled servers
servers["Server $srv"] =
// Install server - the SERVER and CONF variable need to be propagate to the others scripts
withEnv(["SERVER=props.SRV_$srv","CONF=env.DEPLOY_HOME + $srv"])
load env.JENKINSFILES_DIRECTORY + "/server-configuration"
load env.JENKINSFILES_DIRECTORY + "/server-deploiement"
load env.JENKINSFILES_DIRECTORY + "/server-postconfig"
load env.JENKINSFILES_DIRECTORY + "/server-start"
parallel servers
server-config
#!/usr/bin/env groovy
node
// Some declaration
stage('configure serveur')
// The variable SERVER and CONF must be visible here
// is it possible ?
sh "ssh -X " + env.USER +"@$env.SERVER 'sh echo "$env.CONF"'"
Thank you very much. I tried withEnv and it worked. I was about to write a comment when I saw your answer
– Sylvain Goubaud
Nov 10 at 20:10
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
withEnv
is what you are looking for
node
// Some declaration and code
stage('Prepare deploy')
// Create a talbe for the servers lists
def servers = [:]
// For each server know, if deployment is enabled
// deploy resources
params.each srv, value ->
if ("$value" == "true")
// add the current current to the enabled servers
servers["Server $srv"] =
// Install server - the SERVER and CONF variable need to be propagate to the others scripts
withEnv(["SERVER=props.SRV_$srv","CONF=env.DEPLOY_HOME + $srv"])
load env.JENKINSFILES_DIRECTORY + "/server-configuration"
load env.JENKINSFILES_DIRECTORY + "/server-deploiement"
load env.JENKINSFILES_DIRECTORY + "/server-postconfig"
load env.JENKINSFILES_DIRECTORY + "/server-start"
parallel servers
server-config
#!/usr/bin/env groovy
node
// Some declaration
stage('configure serveur')
// The variable SERVER and CONF must be visible here
// is it possible ?
sh "ssh -X " + env.USER +"@$env.SERVER 'sh echo "$env.CONF"'"
Thank you very much. I tried withEnv and it worked. I was about to write a comment when I saw your answer
– Sylvain Goubaud
Nov 10 at 20:10
add a comment |
up vote
1
down vote
accepted
withEnv
is what you are looking for
node
// Some declaration and code
stage('Prepare deploy')
// Create a talbe for the servers lists
def servers = [:]
// For each server know, if deployment is enabled
// deploy resources
params.each srv, value ->
if ("$value" == "true")
// add the current current to the enabled servers
servers["Server $srv"] =
// Install server - the SERVER and CONF variable need to be propagate to the others scripts
withEnv(["SERVER=props.SRV_$srv","CONF=env.DEPLOY_HOME + $srv"])
load env.JENKINSFILES_DIRECTORY + "/server-configuration"
load env.JENKINSFILES_DIRECTORY + "/server-deploiement"
load env.JENKINSFILES_DIRECTORY + "/server-postconfig"
load env.JENKINSFILES_DIRECTORY + "/server-start"
parallel servers
server-config
#!/usr/bin/env groovy
node
// Some declaration
stage('configure serveur')
// The variable SERVER and CONF must be visible here
// is it possible ?
sh "ssh -X " + env.USER +"@$env.SERVER 'sh echo "$env.CONF"'"
Thank you very much. I tried withEnv and it worked. I was about to write a comment when I saw your answer
– Sylvain Goubaud
Nov 10 at 20:10
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
withEnv
is what you are looking for
node
// Some declaration and code
stage('Prepare deploy')
// Create a talbe for the servers lists
def servers = [:]
// For each server know, if deployment is enabled
// deploy resources
params.each srv, value ->
if ("$value" == "true")
// add the current current to the enabled servers
servers["Server $srv"] =
// Install server - the SERVER and CONF variable need to be propagate to the others scripts
withEnv(["SERVER=props.SRV_$srv","CONF=env.DEPLOY_HOME + $srv"])
load env.JENKINSFILES_DIRECTORY + "/server-configuration"
load env.JENKINSFILES_DIRECTORY + "/server-deploiement"
load env.JENKINSFILES_DIRECTORY + "/server-postconfig"
load env.JENKINSFILES_DIRECTORY + "/server-start"
parallel servers
server-config
#!/usr/bin/env groovy
node
// Some declaration
stage('configure serveur')
// The variable SERVER and CONF must be visible here
// is it possible ?
sh "ssh -X " + env.USER +"@$env.SERVER 'sh echo "$env.CONF"'"
withEnv
is what you are looking for
node
// Some declaration and code
stage('Prepare deploy')
// Create a talbe for the servers lists
def servers = [:]
// For each server know, if deployment is enabled
// deploy resources
params.each srv, value ->
if ("$value" == "true")
// add the current current to the enabled servers
servers["Server $srv"] =
// Install server - the SERVER and CONF variable need to be propagate to the others scripts
withEnv(["SERVER=props.SRV_$srv","CONF=env.DEPLOY_HOME + $srv"])
load env.JENKINSFILES_DIRECTORY + "/server-configuration"
load env.JENKINSFILES_DIRECTORY + "/server-deploiement"
load env.JENKINSFILES_DIRECTORY + "/server-postconfig"
load env.JENKINSFILES_DIRECTORY + "/server-start"
parallel servers
server-config
#!/usr/bin/env groovy
node
// Some declaration
stage('configure serveur')
// The variable SERVER and CONF must be visible here
// is it possible ?
sh "ssh -X " + env.USER +"@$env.SERVER 'sh echo "$env.CONF"'"
answered Nov 10 at 18:08
Ram Kamath
519314
519314
Thank you very much. I tried withEnv and it worked. I was about to write a comment when I saw your answer
– Sylvain Goubaud
Nov 10 at 20:10
add a comment |
Thank you very much. I tried withEnv and it worked. I was about to write a comment when I saw your answer
– Sylvain Goubaud
Nov 10 at 20:10
Thank you very much. I tried withEnv and it worked. I was about to write a comment when I saw your answer
– Sylvain Goubaud
Nov 10 at 20:10
Thank you very much. I tried withEnv and it worked. I was about to write a comment when I saw your answer
– Sylvain Goubaud
Nov 10 at 20:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241133%2fis-it-possible-to-propagate-variable-from-a-jenkins-pipeline-job-script-to-loade%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I got another hint on your script: since the loaded scripts have their own node block the parallel call should not be done inside a node block as this will only block a node for no reason. If the runtime is a few secs only this won’t hurt. However if there’s a shortage in nodes you may block one node until another one will be free... Just saying:)
– Joerg S
Nov 11 at 7:16
Hum... Thanks. If I understand what you said, it's better if I do that ? def server .... node .... parralel server ? (parralel call is inside the node ?) Or I suppress the node block in the loaded script ?
– Sylvain Goubaud
Nov 12 at 18:55
This will depend on your need. If you'll be able to reuse that node I'd rather prefer it that way as - for large Jenkins instances - opening a new node block may take up to some minutes.
– Joerg S
Nov 13 at 17:08
Thanks for your answer. I made some tries. So, for my needs, It's better is I delete the node block in server-configuration file. Thanks
– Sylvain Goubaud
Nov 14 at 20:24