Skip to content
Snippets Groups Projects
Commit 6737a1e5 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

jobs/tools: Add jenkins-jobs-builder job

This job is responsible of updating the Jenkins jobs configuration
when executed. It will be triggered when pushing changes to the
swh-jenkins-jobs repository.

When triggered from a GitLab merge request, Jenkins jobs configuration
is not updated, only proper jobs generation is checked.
parent 4e08f093
No related branches found
No related tags found
1 merge request!145jobs/tools: Add jenkins-jobs-builder job
pipeline {
agent any
stages {
stage('Checkout Repository') {
steps {
updateGitlabCommitStatus name: 'jenkins', state: 'running'
checkout([
$class: 'GitSCM',
branches: [[name: env.gitlabSourceBranch ?: "master"]],
userRemoteConfigs: [[
url: '{{gitlab_url}}/{{gitlab_project_name}}.git',
refspec: '+refs/heads/*:refs/remotes/origin/* \
+refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*'
]],
])
}
}
stage('Test Jenkins jobs can be generated') {
steps {
sh('tox')
}
}
stage('Update Jenkins jobs and setup gitlab webhooks') {
when {
// really update jenkins jobs configuration when pushing commits to master
// or when manually triggering the job from Jenkins UI
expression { !env.gitlabMergeRequestIid }
anyOf {
expression { !env.gitlabSourceBranch }
expression { "${env.gitlabSourceBranch}" == "master" }
}
}
steps {
script {
sh('tox -- update --delete-old')
}
}
}
}
post {
failure {
updateGitlabCommitStatus name: 'jenkins', state: 'failed'
}
success {
updateGitlabCommitStatus name: 'jenkins', state: 'success'
}
aborted {
updateGitlabCommitStatus name: 'jenkins', state: 'canceled'
}
}
}
- job-template:
name: jenkins-tools/{project_name}
project-type: pipeline
description: Update jenkins jobs and setup GitLab webhooks
node: built-in
gitlab_url: https://gitlab-staging.swh.network
gitlab_connection_name: gitlab-staging
gitlab_project_name: swh/infra/ci-cd/swh-jenkins-jobs
properties:
- build-discarder:
days-to-keep: 7
properties:
- gitlab:
connection: "{gitlab_connection_name}"
triggers:
- gitlab:
trigger-push: true
trigger-merge-request: true
add-ci-message: true
cancel-pending-builds-on-update: true
# secret jenkins token is generated when executing tox
secret-token: !include-raw: jobs/templates/jenkins-token
dsl: !include-jinja2: jenkins-jobs-builder.groovy.j2
# we use a project and a job template here as we need jinja2 processing
- project:
name: swh-jenkins-jobs-builder
project_name: swh-jenkins-jobs-builder
jobs:
- "jenkins-tools/{project_name}"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment