Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9124037
D8982.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D8982.diff
View Options
diff --git a/jobs/tools/jenkins-jobs-builder.groovy.j2 b/jobs/tools/jenkins-jobs-builder.groovy.j2
new file mode 100644
--- /dev/null
+++ b/jobs/tools/jenkins-jobs-builder.groovy.j2
@@ -0,0 +1,56 @@
+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'
+ }
+ }
+}
diff --git a/jobs/tools/jenkins-jobs-builder.yaml b/jobs/tools/jenkins-jobs-builder.yaml
new file mode 100644
--- /dev/null
+++ b/jobs/tools/jenkins-jobs-builder.yaml
@@ -0,0 +1,31 @@
+- 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}"
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jun 20, 6:35 PM (2 w, 23 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3213795
Attached To
D8982: jobs/tools: Add jenkins-jobs-builder job
Event Timeline
Log In to Comment