【问题标题】:How to create a Jenkins Job with parameters using ansible?如何使用ansible创建带参数的Jenkins Job?
【发布时间】:2023-02-03 18:35:11
【问题描述】:

我在 Jenkins Job Creation 中需要使用 Ansible 参数的帮助。我检查了很多文件,但帮助不大。

我检查了https://docs.ansible.com/ansible/latest/collections/community/general/jenkins_job_module.html 但没有得到需要在 templates/test.xml 中添加的内容?

- name: Create a jenkins job using basic authentication
  community.general.jenkins_job:
    config: "{{ lookup('file', 'templates/test.xml') }}"
    name: test
    password: admin
    url: http://localhost:8080
    user: admin

【问题讨论】:

  • 在你的服务器上的 jenkins 工作树上看到那些 config.xml 文件了吗?这是一个很好的起点。如果您不能直接访问树,使用 curl 或您最喜欢的浏览器获取 http:///<USER>:<API_TOKEN>@your.jenkins.tld/job/JOBNAME/config.xml 应该会为您提供相应的文件。

标签: jenkins ansible ansible-template


【解决方案1】:

下面是一个 XML 格式的简单 Jenkins 作业配置示例,您可以将其用作起点:

<?xml version='1.0' encoding='UTF-8'?>
<project>
  <description>Example Jenkins job with parameters</description>
  <keepDependencies>false</keepDependencies>
  <properties>
    <hudson.model.ParametersDefinitionProperty>
      <parameterDefinitions>
        <hudson.model.StringParameterDefinition>
          <name>param1</name>
          <description>Example parameter</description>
          <defaultValue>value1</defaultValue>
        </hudson.model.StringParameterDefinition>
      </parameterDefinitions>
    </hudson.model.ParametersDefinitionProperty>
  </properties>
  <scm class="hudson.scm.NullSCM"/>
  <canRoam>true</canRoam>
  <disabled>false</disabled>
  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <triggers/>
  <concurrentBuild>false</concurrentBuild>
  <builders>
    <hudson.tasks.Shell>
      <command>echo "Hello, world!"</command>
    </hudson.tasks.Shell>
  </builders>
  <publishers/>
  <buildWrappers/>
</project>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 2020-10-14
    • 1970-01-01
    • 1970-01-01
    • 2017-12-17
    相关资源
    最近更新 更多