我在Ubuntu 16.04上运行Jenkins 2.140服务器,以及使用Ansible 2.6.2的Ansible AWX 1.0.7.2服务器。
我正在Jenkins中创建一个作业,它在我的Ansible AWX服务器上运行一个模板。我还有其他几个Jenkins作业,它们运行的模板都可以工作,所以我知道我为此使用的一般配置是可以的
然而,当我使用使用JobDSL的种子作业创建Jenkins作业时,该作业在Ansible AWX步骤失败,输出为:
11:50:42 [EnvInject] - Loading node environment variables.
11:50:42 Building remotely on windows-slave (excel Windows orqaheadless windows) in workspace C:JenkinsSlaveworkspacecreate-ec2-instance-2
11:50:42 ERROR: Build step failed with exception
11:50:42 java.lang.NullPointerException
11:50:42 at org.jenkinsci.plugins.ansible_tower.AnsibleTower.perform(AnsibleTower.java:129)
11:50:42 at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
11:50:42 at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
11:50:42 at hudson.model.Build$BuildExecution.build(Build.java:206)
11:50:42 at hudson.model.Build$BuildExecution.doRun(Build.java:163)
11:50:42 at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
11:50:42 at hudson.model.Run.execute(Run.java:1815)
11:50:42 at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
11:50:42 at hudson.model.ResourceController.execute(ResourceController.java:97)
11:50:42 at hudson.model.Executor.run(Executor.java:429)
11:50:42 Build step 'Ansible Tower' marked build as failure
11:50:42 [BFA] Scanning build for known causes...
11:50:42 [BFA] No failure causes found
11:50:42 [BFA] Done. 0s
11:50:42 Started calculate disk usage of build
11:50:42 Finished Calculation of disk usage of build in 0 seconds
11:50:42 Started calculate disk usage of workspace
11:50:42 Finished Calculation of disk usage of workspace in 0 seconds
11:50:42 Finished: FAILURE
这个输出实际上并没有给我任何可以使用的东西,尤其是因为我不是Java专家。
我手动配置Jenkins作业,一切都很好。这是工作作业的config.xml
(仅AWX部分(。请注意,所有这些额外的变量都是在作业的早期作为参数传入的:
<builders>
<org.jenkinsci.plugins.ansible__tower.AnsibleTower plugin="ansible-tower@0.9.0">
<towerServer>AWX Server</towerServer>
<jobTemplate>create-ec2-instance</jobTemplate>
<extraVars>
key_name: ${key_name} ec2_termination_protection: ${ec2_termination_protection} vpc_subnet_id: ${vpc_subnet_id} security_groups: ${security_groups} instance_type: ${instance_type} instance_profile_name: ${instance_profile_name} assign_public_ip: ${assign_public_ip} region: ${region} image: ${image} instance_tags: ${instance_tags} ec2_wait_for_create: ${ec2_wait_for_create} ec2_wait_for_create_timeout: ${ec2_wait_for_create_timeout} exact_count: ${exact_count} delete_volume_on_termination: ${delete_volume_on_termination} data_disk_size: ${data_disk_size} private_domain: ${private_domain} route53_private_record_ttl: ${route53_private_record_ttl} dns_record: ${dns_record} elastic_ip: ${elastic_ip}
</extraVars>
<jobTags/>
<skipJobTags/>
<jobType>run</jobType>
<limit/>
<inventory/>
<credential/>
<verbose>true</verbose>
<importTowerLogs>true</importTowerLogs>
<removeColor>false</removeColor>
<templateType>job</templateType>
<importWorkflowChildLogs>false</importWorkflowChildLogs>
</org.jenkinsci.plugins.ansible__tower.AnsibleTower>
</builders>
来自失败的JobDSL生成的作业的config.xml
,在我看来是一样的:
<builders>
<org.jenkinsci.plugins.ansible__tower.AnsibleTower>
<towerServer>AWX Server</towerServer>
<jobTemplate>create-ec2-instance</jobTemplate>
<jobType>run</jobType>
<templateType>job</templateType>
<extraVars>
key_name: ${key_name} ec2_termination_protection: ${ec2_termination_protection} vpc_subnet_id: ${vpc_subnet_id} security_groups: ${security_groups} instance_type: ${instance_type} instance_profile_name: ${instance_profile_name} assign_public_ip: ${assign_public_ip} region: ${region} image: ${image} instance_tags: ${instance_tags} ec2_wait_for_create: ${ec2_wait_for_create} ec2_wait_for_create_timeout: ${ec2_wait_for_create_timeout} exact_count: ${exact_count} delete_volume_on_termination: ${delete_volume_on_termination} data_disk_size: ${data_disk_size} private_domain: ${private_domain} route53_private_record_ttl: ${route53_private_record_ttl} dns_record: ${dns_record} elastic_ip: ${elastic_ip}
</extraVars>
<verbose>true</verbose>
<importTowerLogs>true</importTowerLogs>
</org.jenkinsci.plugins.ansible__tower.AnsibleTower>
</builders>
因此,JobDSL生成的作业总是会有一些预期的差异,比如缺少空字段,但我们所有(成功的(其他作业都遵循这个过程。
JobDSL脚本在这里:
configure { project ->
project / 'builders ' << 'org.jenkinsci.plugins.ansible__tower.AnsibleTower' {
towerServer 'AWX Server'
jobTemplate ('create-ec2-instance')
templateType 'job'
jobType 'run'
extraVars('''key_name: ${key_name}
ec2_termination_protection: ${ec2_termination_protection}
vpc_subnet_id: ${vpc_subnet_id}
security_groups: ${security_groups}
instance_type: ${instance_type}
instance_profile_name: ${instance_profile_name}
assign_public_ip: ${assign_public_ip}
region: ${region} image: ${image}
instance_tags: ${instance_tags}
ec2_wait_for_create: ${ec2_wait_for_create}
ec2_wait_for_create_timeout: ${ec2_wait_for_create_timeout}
exact_count: ${exact_count}
delete_volume_on_termination: ${delete_volume_on_termination}
data_disk_size: ${data_disk_size}
private_domain: ${private_domain}
route53_private_record_ttl: ${route53_private_record_ttl}
dns_record: ${dns_record}
elastic_ip: ${elastic_ip}''')
verbose 'true'
importTowerLogs 'true'
}
}
在我看来,这生成的作业在UI(以及XML(中看起来是相同的,但当我运行它时,我总是失败。很明显,我错过了一些东西,但如果我看到了什么,我一辈子都做不到。
尽管其他AWX作业都是在没有此功能的情况下构建的,但我添加了缺失的(空(字段,作业开始成功。
因此,将我的JobDSL脚本更改为:
configure { project ->
project / 'builders ' << 'org.jenkinsci.plugins.ansible__tower.AnsibleTower' {
towerServer 'AWX Server'
jobTemplate ('create-ec2-instance')
extraVars('''key_name: ${key_name}
ec2_termination_protection: ${ec2_termination_protection}
vpc_subnet_id: ${vpc_subnet_id}
security_groups: ${security_groups}
instance_type: ${instance_type}
instance_profile_name: ${instance_profile_name}
assign_public_ip: ${assign_public_ip}
region: ${region}
image: ${image}
instance_tags: ${instance_tags}
ec2_wait_for_create: ${ec2_wait_for_create}
ec2_wait_for_create_timeout: ${ec2_wait_for_create_timeout}
exact_count: ${exact_count}
delete_volume_on_termination: ${delete_volume_on_termination}
data_disk_size: ${data_disk_size}
private_domain: ${private_domain}
route53_private_record_ttl: ${route53_private_record_ttl}
dns_record: ${dns_record}
elastic_ip: ${elastic_ip}''')
jobTags ''
skipJobTags ''
jobType 'run'
limit ''
inventory ''
credential ''
verbose 'true'
importTowerLogs 'true'
removeColor ''
templateType 'job'
importWorkflowChildLogs ''
现在正在按预期工作。