Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ranjitkumar518/b53a6674be3dca63b2293c5a06620701 to your computer and use it in GitHub Desktop.
Save ranjitkumar518/b53a6674be3dca63b2293c5a06620701 to your computer and use it in GitHub Desktop.
Jenkins Job Builder Example
- defaults:
name: ci-workflow-provision
description: |
Managed by Jenkins Job Builder. Do not edit via web.
concurrent: true
scm:
- git:
url: 'https://code.engineering.redhat.com/gerrit/ci-ops-central'
branches:
- origin/master
basedir: ci-ops-central
- git:
url: 'https://code.engineering.redhat.com/gerrit/ci-ops-projex'
branches:
- origin/master
basedir: ci-ops-projex
- git:
url: 'https://code.engineering.redhat.com/gerrit/job-runner'
branches:
- origin/master
basedir: job-runner
wrappers:
- default-ci-workflow-wrappers
- defaults:
name: ci-workflow-runtest
description: |
Managed by Jenkins Job Builder. Do not edit via web.
concurrent: true
scm:
- git:
url: 'https://code.engineering.redhat.com/gerrit/ci-ops-central'
branches:
- origin/master
basedir: ci-ops-central
- git:
url: 'http://git.app.eng.bos.redhat.com/git/ci-ops-projex.git'
branches:
- origin/master
basedir: ci-ops-projex
wrappers:
- default-ci-workflow-wrappers
- default-ci-workflow-build-timeout-wrapper
- wrapper:
name: default-ci-workflow-wrappers
wrappers:
- ansicolor
- workspace-cleanup
- timestamps
- wrapper:
name: default-ci-workflow-build-timeout-wrapper
wrappers:
- timeout:
timeout-var: 'BUILD_TIMEOUT'
fail: true
elastic-percentage: 150
elastic-default-timeout: 90
type: elastic
- publisher:
name: default-ci-workflow-publishers
publishers:
- email-ext:
recipients: $DEFAULT_RECIPIENTS
reply-to: $DEFAULT_REPLYTO
content-type: default
subject: $DEFAULT_SUBJECT
body: $DEFAULT_CONTENT
attach-build-log: false
always: true
unstable: true
first-failure: true
not-built: true
aborted: true
regression: true
failure: true
improvement: true
still-failing: true
success: true
fixed: true
still-unstable: true
pre-build: true
matrix-trigger: only-configurations
send-to:
- requester
- recipients
- publisher:
name: default-ci-workflow-runtest-publishers
publishers:
- xunit:
thresholdmode: 'number'
thresholds:
- failed:
unstable: 0
unstablenew: 0
failure: 0
failurenew: 0
- skipped:
unstable: 0
unstablenew: 0
failure: 0
failurenew: 0
types:
- junit:
pattern: '*.xml'
deleteoutput: false
- job-template:
name: 'ci-{project}-{topology}-1-provision'
defaults: ci-workflow-provision
node: master
parameters:
- choice:
name: SITE
choices:
- qeos
- os1
description: |
Site where to provision resources
builders:
- shell: |
#!/bin/bash
export JSLAVENAME={jslavename}
# Provision Jenkins Slave
if [ "$JSLAVENAME" != "master" ]
then
$WORKSPACE/ci-ops-central/bootstrap/provision_jslave.sh --site=$SITE --project_defaults={project_defaults} \
--topology=ci-ops-central/project/config/aio_jslave --ssh_keyfile={ssh_keyfile} \
--jslavename={jslavename} --jslaveflavor={jslaveflavor} --jslaveimage={jslaveimage} \
--jslave_execs={jslave_execs} --jslavecreate --resources_file={jslavename}.json
TR_STATUS=$?
if [ "$TR_STATUS" != 0 ]; then echo "ERROR: Provisioning\nSTATUS: $TR_STATUS"; exit 1; fi
fi
# Provision Test Resources
$WORKSPACE/ci-ops-central/bootstrap/provision_resources.sh --site=$SITE --project_defaults={project_defaults} \
--topology={topology_path}/{topology} --ssh_keyfile={ssh_keyfile} --name={project}
TR_STATUS=$?
files=$(ls $WORKSPACE/*.slave 2>/dev/null)
if [ -e "$files" ]
then
cat $WORKSPACE/*.slave >> $WORKSPACE/RESOURCES.txt
fi
if [ "$TR_STATUS" != 0 ]; then echo "ERROR: Provisioning\nSTATUS: $TR_STATUS"; exit 1; fi
- inject:
properties-file: $WORKSPACE/RESOURCES.txt
publishers:
- archive:
artifacts: '*.txt, *.json'
allow-empty: 'true'
- trigger-parameterized-builds:
- project: '{project}-{topology}-2-runtest'
current-parameters: true
condition: 'SUCCESS'
property-file: $WORKSPACE/RESOURCES.txt
fail-on-missing: true
- project: 'ci-{project}-{topology}-3-teardown'
current-parameters: true
condition: 'UNSTABLE_OR_WORSE'
property-file: $WORKSPACE/RESOURCES.txt
fail-on-missing: true
- default-ci-workflow-publishers
- job-template:
name: '{project}-{topology}-2-runtest'
defaults: ci-workflow-runtest
node: '{jslavename}'
builders:
- copyartifact:
project: 'ci-{project}-{topology}-1-provision'
filter: '*.txt, *.json'
target: $WORKSPACE
- shell: |
#!/bin/bash
export TOPOLOGY={topology}
{testparams}
echo "TOPOLOGY: {topology}"
echo "Ping Jenkins Slave"
ping -c 10 $JSLAVEIP
echo "Jenkins machine info we are running on"
ifconfig
echo "Pinging Test Resources"
echo $EXISTING_NODES | xargs -i -d , ping -c 15 {{}}
cat $WORKSPACE/RESOURCES.txt
pushd $WORKSPACE/ci-ops-projex/tests
nosetests --with-xunit --xunit-file=$WORKSPACE/nosetests.xml
popd
publishers:
- archive:
artifacts: '**/**'
allow-empty: 'true'
- default-ci-workflow-runtest-publishers
- trigger-parameterized-builds:
- project: 'ci-{project}-{topology}-3-teardown'
current-parameters: true
- default-ci-workflow-publishers
- job-template:
name: 'ci-{project}-{topology}-3-teardown'
defaults: ci-workflow-provision
node: master
builders:
- shell: |
#!/bin/bash
export JSLAVETEARDOWN={jslaveteardown}
# Teardown Jenkins Slave
$WORKSPACE/ci-ops-central/bootstrap/teardown_resources.sh --site=$SITE --project_defaults={project_defaults} \
--topology={topology_path}/{topology} --name=$LABEL
TR_STATUS=$?
if [ "$TR_STATUS" != 0 ]; then echo "ERROR: Teardown\nSTATUS: $TR_STATUS"; exit 1; fi
if [ "$JSLAVETEARDOWN" == "True" ]
then
$WORKSPACE/ci-ops-central/bootstrap/teardown_jslave.sh --site=$SITE --project_defaults={project_defaults} \
--topology=ci-ops-central/project/config/aio_jslave --jslavename=$JSLAVENAME \
--jslaveusername={jslaveusername} --jslavepassword={jslavepassword} --jslaveip=$JSLAVEIP --jslaveteardown
TR_STATUS=$?
if [ "$TR_STATUS" != 0 ]; then echo "ERROR: Teardown\nSTATUS: $TR_STATUS"; exit 1; fi
fi
- job-group:
name: ci-workflow-provision-runtest-teardown
jobs:
- 'ci-{project}-{topology}-1-provision'
- '{project}-{topology}-2-runtest'
- 'ci-{project}-{topology}-3-teardown'
- project:
name: ci-workflow-jobs
project: workflow
project_defaults: ci-ops-projex/config/project_defaults
topology_path: ci-ops-projex/config
topology:
- aio_RHEL6-5
- bkr_and_os
- 2comp
- foreman
ssh_keyfile: ci-ops-projex/config/keys/ci-ops-central
tests_path: ci-ops-projex/tests
testparams: echo "I am a test parameter"
jslavename: jslave-projex-slave
jslave_execs: 10
jslaveimage: rhel-6.5_jeos
jslaveflavor: m1.large
jslaveusername: root
jslavepassword: 123456
jslaveteardown: True
jobs:
- ci-workflow-provision-runtest-teardown
[jenkins]
user=
password=
url=http://10.8.50.144/
- defaults:
name: default-service-jobs
logrotate:
numToKeep: 30
artifactNumToKeep: 15
- wrapper:
name: default-service-jjb-jobs-wrapper
wrappers:
- inject-passwords:
global: true
- mask-passwords
- wrapper:
name: default-service-jobs-wrapper
wrappers:
- ansicolor
- workspace-cleanup
- timestamps
- job-template:
name: 'jjb_{jjb_names}'
defaults: default-service-jobs
node: master
description: |
This job builds the other jobs from the definitions for {jjb_names}
Managed by Jenkins Job Builder. Do not edit via web.
retry-count: 3
scm:
- git:
url: 'git://git.app.eng.bos.redhat.com/atomic-ci-jobs.git'
branches:
- origin/master
basedir: atomic-ci-jobs
triggers:
- pollscm: "H/30 * * * *"
wrappers:
- default-service-jobs-wrapper
- default-service-jjb-jobs-wrapper
builders:
- shell: |
cat > $WORKSPACE/config << EOF
[jenkins]
user=$JOB_BUILDER_USER
password=$JOB_BUILDER_PASS
url=$JENKINS_URL
EOF
jenkins-jobs --conf $WORKSPACE/config --ignore-cache update $WORKSPACE/atomic-ci-jobs/project/jobs/{jjb_names}
- project:
name: service-jobs
jjb_names:
- rhelah
- atomic-e2e
- rhel-docker-enablement
- rhel-kub-enablement
- raas-e2e
- appinfra-trigger
- fedora
jobs:
- jjb_{jjb_names}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment