Skip to content

Commit 1696cee

Browse files
authored
Merge pull request #77 from slickoner/bugfix/fix-pipeline-extra-vars-boolean
Fix Boolean support for extra vars in pipeline and add minimal pipeline test
2 parents 1c78933 + 7f84ff8 commit 1696cee

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/main/java/org/jenkinsci/plugins/ansible/workflow/AnsiblePlaybookStep.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ else if (o instanceof String) {
391391
var.setSecretValue(Secret.fromString((String)o));
392392
var.setHidden(true);
393393
}
394+
else if (o instanceof Boolean) {
395+
var.setSecretValue(Secret.fromString(o.toString()));
396+
var.setHidden(true);
397+
}
394398
else if (o instanceof Secret) {
395399
var.setSecretValue((Secret)o);
396400
var.setHidden(true);

src/test/java/org/jenkinsci/plugins/ansible/PipelineTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,16 @@ public void testExtraVarsMap() throws Exception {
6565
));
6666
}
6767

68+
@Test
69+
public void testExtraVarsBoolean() throws Exception {
70+
String pipeline = IOUtils.toString(PipelineTest.class.getResourceAsStream("/pipelines/extraVarsBoolean.groovy"), StandardCharsets.UTF_8);
71+
WorkflowJob workflowJob = jenkins.createProject(WorkflowJob.class);
72+
workflowJob.setDefinition(new CpsFlowDefinition(pipeline, true));
73+
WorkflowRun run1 = workflowJob.scheduleBuild2(0).waitForStart();
74+
jenkins.waitForCompletion(run1);
75+
assertThat(run1.getLog(), allOf(
76+
containsString("ansible-playbook playbook.yml -e ******** -e ********")
77+
));
78+
}
79+
6880
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
pipeline {
2+
agent {
3+
label('test-agent')
4+
}
5+
stages {
6+
stage('Create playbook') {
7+
steps {
8+
writeFile(encoding: 'UTF-8', file: 'playbook.yml', text: '''- hosts: localhost
9+
connection: local
10+
gather_facts: no
11+
tasks:
12+
- debug: msg=test
13+
''')
14+
}
15+
}
16+
stage('Ansible playbook') {
17+
steps {
18+
warnError(message: 'ansible command not found?') {
19+
ansiblePlaybook(
20+
playbook: 'playbook.yml',
21+
extraVars: [foo1: true, foo2: false],
22+
)
23+
}
24+
}
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)