AnsiblePlaybookBuilder does not see any changes done in the environment
Closed this issue · 2 comments
Jenkins and plugins versions report
Environment
Jenkins 2.401.3
Ansible plugin: 253.v4fe719ffdd8a_
Java: openjdk 11.0.19 2023-04-18 LTS
Ansible: core 2.13.11
What Operating System are you using (both controller, and any agents involved in the problem)?
RHEL7
Reproduction steps
node() {
stage('Create Play') {
writeFile file: 'play.yaml', text: """
- hosts: myhost
tasks:
- debug: msg="{{ lookup('env', 'MyVar') }}"
- debug: msg="{{ lookup('env', 'MyAnotherVar') }}"
"""
}
stage('Play') {
env.MyVar = 'WannaSeeThis'
withEnv(['MyAnotherVar=WannaSeeThis']) {
step([
$class: 'AnsiblePlaybookBuilder',
playbook: "play.yaml",
inventory: [
$class: 'InventoryContent',
content: "[myhost]\nlocalhost ansible_connection=local"
],
])
}
}
}
Expected Results
The environment variables I defined within the pipeline are visible inside the play.
Actual Results
The environment variables I defined within the pipeline are not visible inside the play.
Anything else?
The variables are visible in a play if I define variables within the "Prepare an environment for the run" feature in a job configuration.
You are in a pipeline, why using the builder and not the ansiblePlaybook
step ?
The variables are visible in a play if I define variables within the "Prepare an environment for the run" feature in a job configuration.
That's the point, AnsiblePlaybookBuilder is suppose to be used inside freestyle jobs not pipelines.
Using directly the builder will bypass EnvironmentExpander
which compute the environment for a given context
Hello,
First of all, thank you for the fast reply!
You are right we can use the ansiblePlaybook
for our purpose, and we did till we wanted to get the ansibleName
functionality. I thought it was a good idea to predefine every Ansible installation globally and then refer to them via that field in jobs. I can achieve more or less the same with the installation
field from ansiblePlaybook
.
"That's the point, AnsiblePlaybookBuilder is suppose to be used inside freestyle jobs not pipelines."
I was not aware of it. Thank you for the explanation! I guess the question is answered so please feel free to close it.
Kind regard