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

jobs: Add GitLab support for maven-index-exporter

Add a job that will be executed when pushing tags to the maven-indexer-exporter
repository hosted on SWH GitLab.

Also rename configuration file to something more meaningful and update pipeline
script to match the style of the other ones in that repository.
parent a3509899
No related branches found
No related tags found
No related merge requests found
- job-template:
- job-template: &build_and_push
name: "{name}/build-and-push"
description: Build the docker image and publish it to a registry
node: built-in
project-type: pipeline
auth-token: 'ph4br1cat0r'
dsl:
!include-jinja2: templates/swh-build-docker-image.groovy.j2
auth-token: "ph4br1cat0r"
dsl: !include-jinja2: templates/swh-build-docker-image.groovy.j2
parameters:
- string:
name: TAG
description: Tag to build the image and then use as name
- job-template:
name: "{name}/gitlab-build-and-push"
description: Build the docker image and publish it to a registry (GitLab)
auth-token:
parameters:
gitlab_project: true
gitlab_project_name: swh/devel/fixtures/maven-index-exporter
properties:
- gitlab:
connection: "{gitlab_connection_name}"
triggers:
- gitlab:
trigger-push: true
trigger-merge-request: false
add-ci-message: true
# secret jenkins token is generated when executing tox
secret-token: !include-raw: jobs/templates/jenkins-token
<<: *build_and_push
- project:
name: DLSMAVEXP
display-name: maven-index-exporter
......@@ -19,3 +37,4 @@
jobs:
- "{name}"
- "{name}/build-and-push"
- "{name}/gitlab-build-and-push"
......@@ -2,7 +2,13 @@ def repo_name = "{{repo_name}}"
// Normalize to "latest" if we build from head commit (main or master)
// Otherwise, keep the transmitted tag
{%- if gitlab_project %}
// remove refs/tags/ prefix from source branch
def tag = env.gitlabSourceBranch.substring(10)
{%- else %}
def tag = params.TAG
{%- endif %}
def tag_name = ( tag == "origin/main" || tag == "origin/master" ) ? "latest" : tag
// The following is configured in jenkins manually:
......@@ -27,35 +33,67 @@ def image_label = env.BUILD_TAG
// - push: publish to the registry
// TAG, REGISTRY_URL must be provided
node('built-in') {
stage ('Pre-cleanup') {
cleanWs()
}
stage('Checkout Repository') {
checkout([
$class: 'GitSCM',
branches: [[name: tag]],
userRemoteConfigs: [[
url: "https://forge.softwareheritage.org/source/${repo_name}/",
]],
])
}
def dockerImage
stage ('Build image') {
sh "make build TAG=${tag} IMAGE_LABEL=${image_label}"
}
stage ('Push image') {
// first make sure the image is ok
sh "make test TAG=${tag}"
// then publish it
docker.withRegistry("https://${registry_url}", dockerCredentialsKeyID) {
sh "make push TAG=${tag} REGISTRY_URL=${registry_url}"
pipeline {
agent any
stages {
stage ('Pre-cleanup') {
steps {
cleanWs()
}
}
stage('Checkout Repository') {
steps {
{%- if gitlab_project %}
updateGitlabCommitStatus name: 'jenkins', state: 'running'
{%- endif %}
checkout([
$class: 'GitSCM',
branches: [[name: tag]],
userRemoteConfigs: [[
{%- if not gitlab_project %}
url: "https://forge.softwareheritage.org/source/${repo_name}/",
{%- else %}
url: "{{gitlab_url}}/{{gitlab_project_name}}"
{%- endif %}
]],
])
}
}
stage ('Build image') {
steps {
sh "make build TAG=${tag} IMAGE_LABEL=${image_label}"
}
}
stage ('Push image') {
steps {
script {
// first make sure the image is ok
sh "make test TAG=${tag}"
// then publish it
docker.withRegistry("https://${registry_url}", dockerCredentialsKeyID) {
sh "make push TAG=${tag} REGISTRY_URL=${registry_url}"
}
}
}
}
}
post {
always {
// finally clean workspace
cleanWs()
// and locally built image (resulting from the current jenkins build)
sh "make clean IMAGE_LABEL=${image_label}"
// finally clean workspace
cleanWs()
}
{%- if gitlab_project %}
failure {
updateGitlabCommitStatus name: 'jenkins', state: 'failed'
}
success {
updateGitlabCommitStatus name: 'jenkins', state: 'success'
}
aborted {
updateGitlabCommitStatus name: 'jenkins', state: 'canceled'
}
{%- endif %}
}
}
......@@ -32,6 +32,8 @@ pipeline {
true, true, false)
setupGitlabWebhook("swh/infra/swh-mirror", "DFP/gitlab-run-tests",
true, true, false)
setupGitlabWebhook("swh/devel/fixtures/maven-index-exporter", "DLSMAVEXP/gitlab-build-and-push",
false, false, true)
projects = readYaml(file: 'jobs/swh-packages.yaml')
for (project in projects) {
......
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