Jenkinsfile environment setup help

778 views
Skip to first unread message

Tuomas-Matti Soikkeli

unread,
Jul 6, 2016, 11:20:02 AM7/6/16
to Jenkins Users
Good day.

I'm building on Jenkins 2.0 with pipelines and jenkinsfiles from SCM to achieve continuous delivery for my project. 

However I'm facing issues with groovy workflow to source my environment variables for ansible.

I'm running Ansible from source so I need to run:

$ source ansible/hacking/env-setup

However when I run this in my Jenkinsfile:

stage "deploy"
sh
'source /opt/ansible/hacking/env-setup"
sh '
ansible --version'


My environent variables from env-setup are gone. How would one include envs from setup script to env.PATH?

env-setup setups python dependencies and correct paths. You can check out the environment script from: https://raw.githubusercontent.com/ansible/ansible/devel/hacking/env-setup

Any hints how to work out this?

Best regards, t-m 




Eric Pyle

unread,
Jul 6, 2016, 2:26:20 PM7/6/16
to jenkins...@googlegroups.com

To apply environment variables, you have to wrap your code in a withEnv block, whose argument is an array of strings of the form 'VARIABLE=value'. So you could read the env-setup file and go through line by line building up an environment array, then use that array variable in the withEnv block. Or you could put all your Ansible commands in a shell script, and include the "source /opt/ansible/hacking/env-setup" as one of the first lines in the script. You could use the writeFile step to create such a shell script on the fly if desired.

Eric
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/457a6cf4-2f48-4711-bea8-e48227f9ac3d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages