Automatically generating Jenkins jobs: Step-by-step guide
pip install virtualenv
virtualenv .venv
source .venv/bin/activate
pip install jenkins-job-builder
mkdir jenkins-job-auto-create ; cd jenkins-job-auto-create
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=Falsevim 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"
}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: 0Jenkins job created automatic
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}'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: 0install
jenkins-autojobsQuck start Guide
Quck Start
Job Definitions