Skip to content
Snippets Groups Projects
jenkins-jobs-builder.groovy.j2 1.54 KiB
Newer Older
def branch = "master"
if (env.gitlabMergeRequestIid) {
  branch = "merge-requests/${env.gitlabMergeRequestIid}"
} else if (env.gitlabSourceBranch) {
  branch = env.gitlabSourceBranch
}


  stages {

    stage('Checkout Repository') {
      steps {
        updateGitlabCommitStatus name: 'jenkins', state: 'running'
        checkout([
          $class: 'GitSCM',
          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
        anyOf {
          expression { "${env.gitlabActionType}" == "PUSH" && "${env.gitlabBranch}" == "master" }
          expression { !env.gitlabActionType }
          sh('tox -- update --delete-old --jobs-only')
            job: '/jenkins-tools/setup-gitlab-webhooks'
    {% filter indent(width=4) %}
      {%- include 'jobs/templates/includes/update-gitlab-commit-status.groovy.j2' -%}
    {% endfilter %}