Skip to content

incoming-tag: Add stage to trigger impacted docker images rebuild job

It's installed just after the pypi upload stage.

It's not waiting for the end of this stage to finish as nothing is really waiting for it. So debian packaging build should trigger in parallel. A quiet period of 10s has been inserted for that new job to let pypi.org some time to index the new version. Locally, After installing the job. I've adapted the swh.core job [1] so it can be executed (without all stages and in a dry-run mode fashion so nothings gets pushed).

It took a bit of time though because (still running btw):

  1. the required java agent (to run docker jobs) was not activated ¯\_(ツ)_/¯ (so jobs were waiting indefinitely ;)
  2. I tested the main module swh.core (which is a bit harsh for my machines given everything depend on it)

2023-06-27_14-49-15

2023-06-27_14-52-48

2023-06-27_15-13-42

2023-06-27_15-13-58

Refs. swh/infra/sysadm-environment#4724 (closed)

[1] After installing the job through the job builder.

def tags="v2.22.2"

pipeline {
  agent none
  stages {

    stage('Refresh tag list') {
      agent any
      steps {
        updateGitlabCommitStatus name: 'jenkins', state: 'running'
        checkout([
          $class: 'GitSCM',
          userRemoteConfigs: [[
            name:'origin', url: 'https://gitlab.softwareheritage.org/swh/devel/swh-core.git',
            refspec: '+refs/tags/*:refs/remotes/origin/tags*'
          ]],
          branches: [[
            name: "${tags}"
          ]],
          browser: [
            $class: 'GitLab',
            repoUrl: 'https://gitlab.softwareheritage.org/swh/devel/swh-core'
          ],
          extensions: [[$class: 'CloneOption', honorRefspec: true]],
        ])
      }
    }

    stage('Build and upload PyPI package') {
      when {
         expression { true == false }
     }
      steps {
        build(
          job: '/DCORE/pypi-upload',
          parameters: [
            // remove refs/tags/ prefix from source branch
            string(name: 'GIT_TAG', value: env.gitlabSourceBranch.substring(10)),
            string(name: 'PYPI_HOST', value: 'pypi.org'),
          ],
          wait: true,
        )
      }
    }

    stage('Update Debian packaging for new release') {

      when {
        expression { true == false }
      }

      steps {
        build(
          job: '/debian/packages/DCORE/update-for-release',
          parameters: [
            // remove refs/tags/ prefix from source branch
            string(name: 'GIT_TAG', value: env.gitlabSourceBranch.substring(10)),
          ],
          wait: true,
        )
      }
    }

    stage('Build Debian package') {
      when {
        expression { true == false }
      }
      steps {
        build(
          job: '/debian/packages/DCORE/gbp-buildpackage',
          parameters: [
            // remove refs/tags/ prefix from source branch
            string(name: 'GIT_REVISION', value: env.gitlabSourceBranch.substring(10)),
            booleanParam(name: 'DO_UPLOAD', value: true),
          ],
          wait: true,
        )
      }
    }

    stage('Build Docker Image(s) depending on new release') {
      when {
        // The tag is in the right format
        expression { "refs/tags/${tags}" ==~ /refs\/tags\/v\d+(:?\.\d+)+(:?(:?a|b|rc)\d+)?/ }
        // Job to build images exist
        expression { jenkinsJobExists('/swh-apps/build-docker-images') }
      }
      steps {
        build(
          job: '/swh-apps/build-docker-images',
          parameters: [
            string(name: 'MODULE', value: 'swh.core'),
            // VERSION is the actual tag without 'refs/tags/' prefix
            string(name: 'VERSION', value: "refs/tags/${tags}"),
            booleanParam(name: 'DRY_RUN', value: true),
            booleanParam(name: 'CLEANUP_IMAGES', value: false)
          ],
          wait: true,
        )
      }
    }
  }

  post {
    failure {
      script {
        updateGitlabCommitStatus name: 'jenkins', state: 'failed'
        if (env.gitlabMergeRequestIid) {
          def message = "Jenkins job [${env.JOB_NAME} #${env.BUILD_ID}]"
          message += "(${env.BUILD_URL}) {- failed -}.<br/>"
          message += "See [Console Output](${env.BUILD_URL}console) and "
          message += "[Coverage Report](${env.BUILD_URL}coverage) for more details."
          addGitLabMRComment comment: message
        }
      }
    }
    success {
      script {
        updateGitlabCommitStatus name: 'jenkins', state: 'success'
        if (env.gitlabMergeRequestIid) {
          def message = "Jenkins job [${env.JOB_NAME} #${env.BUILD_ID}]"
          message += "(${env.BUILD_URL}) {+ succeeded +}.<br/>"
          message += "See [Console Output](${env.BUILD_URL}console) and "
          message += "[Coverage Report](${env.BUILD_URL}coverage) for more details."
          addGitLabMRComment comment: message
        }
      }
    }
    aborted {
      updateGitlabCommitStatus name: 'jenkins', state: 'canceled'
    }
  }
}

def jenkinsJobExists(String name) {
  def instance = jenkins.model.Jenkins.instance
  return instance.getItemByFullName(name) != null
}
Edited by Antoine R. Dumont

Merge request reports