How to Automate Jenkins job configurations as code

Automatically generating Jenkins jobs: Step-by-step guide

  1. pip install virtualenv

  2. virtualenv .venv

  3. source .venv/bin/activate

  4. pip install jenkins-job-builder

  5. mkdir jenkins-job-auto-create ; cd jenkins-job-auto-create

  6. vim jenkins_jobs.ini

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    [jenkins]
    user=shuke
    password=aslongas
    url=http://jenkins.shuke.com:8080

    [job_builder]
    ignore_cache=True
    keep_descriptions=False
    include_path=.
    recursive=False
    allow_duplicates=False
  7. vim project_pipeline_test01.yaml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    (base) ➜  jenkins_jobs cat project_pipeline_test01.yaml
    - job:
    name: Jenkins-auto-config
    project-type: pipeline
    dsl: |
    @Library('CIPipelineUtilities') _
    testSuite {
    envName="BTS_EU"
    suiteName="MonitorTest"
    }
  8. jenkins-jobs –conf jenkins_jobs.ini update project_pipeline_test01.yaml

    1
    2
    3
    4
    5
    6
    7
    (base) ➜  jenkins_jobs jenkins-jobs --conf jenkins_jobs.ini update project_pipeline_test01.yaml
    INFO:jenkins_jobs.cli.subcommand.update:Updating jobs in ['project_pipeline_test01.yaml'] ([])
    INFO:jenkins_jobs.builder:Number of jobs generated: 1
    INFO:jenkins_jobs.builder:Reconfiguring jenkins job Jenkins-auto-config
    INFO:jenkins_jobs.cli.subcommand.update:Number of jobs updated: 1
    INFO:jenkins_jobs.builder:Number of views generated: 0
    INFO:jenkins_jobs.cli.subcommand.update:Number of views updated: 0
  9. Jenkins job created automatic

  10. folder-jobs.yaml

    1
    2
    3
    4
    5
    6
    7
    8
    - job-template:
    name: 'folder-{name}'
    project-type: folder

    - project:
    name: devops
    jobs:
    - 'folder-{name}'
  11. create folder-jobs

    1
    2
    3
    4
    5
    6
    7
    (base) ➜  jenkins_jobs jenkins-jobs --conf jenkins_jobs.ini update folder-jobs.yaml
    INFO:jenkins_jobs.cli.subcommand.update:Updating jobs in ['folder-jobs.yaml'] ([])
    INFO:jenkins_jobs.builder:Number of jobs generated: 1
    INFO:jenkins_jobs.builder:Reconfiguring jenkins job folder-devops
    INFO:jenkins_jobs.cli.subcommand.update:Number of jobs updated: 1
    INFO:jenkins_jobs.builder:Number of views generated: 0
    INFO:jenkins_jobs.cli.subcommand.update:Number of views updated: 0
  12. install
    jenkins-autojobs

  13. Quck start Guide
    Quck Start
    Job Definitions

本文标题:How to Automate Jenkins job configurations as code

文章作者:shuke

发布时间:2020年06月08日 - 17:06

最后更新:2020年06月08日 - 17:06

原始链接:https://shuke163.github.io/2020/06/08/How-to-Automate-Jenkins-job-configurations-as-code/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

-------------本文结束感谢您的阅读-------------

本文标题:How to Automate Jenkins job configurations as code

文章作者:shuke

发布时间:2020年06月08日 - 17:06

最后更新:2020年06月08日 - 17:06

原始链接:https://shuke163.github.io/2020/06/08/How-to-Automate-Jenkins-job-configurations-as-code/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

0%