#70 PVHEALTH-126:Integrate Gerrit
Merged 4 years ago by pbortlov. Opened 4 years ago by pbortlov.
pbortlov/c3i-library gerrit-integration  into  master

file modified
+14
@@ -50,6 +50,20 @@ 

      * Hub Address: tcp://hub.fedoraproject.org:9940

      * Publish Address: tcp://hub.fedoraproject.org:9940

  

+ ### Integration with Gerrit:

+ * Server name defined by `c3i_gerrit_server`

+ 

+ #### Setup Gerrit trigger in Jenkins

+ * Click on 'Manage Jenkins'

+ * Go to 'Gerrit trigger'

+   * Add new server

+     * Add name the same you use in `c3i_gerrit_server`

+     * Choose -> __Gerrit Server with Default Configurations__

+     * Specify -> Hostname, Frontend URL, Username, SSH Keyfile and SSH Keyfile Password -> press __Test connection__

+       * Note: If you have an issue with ssh key try to create the ssh key on centos.

+ #### Set up Gerrit access right for the account

+ * use [Gerrit trigger plugin - Set up - Gerrit access right](https://plugins.jenkins.io/gerrit-trigger/) documentation

+ 

  ### Integration with Ansible tower

  Postmerge and Promotion workflows can trigger Tower job when new container image is created, tested and uploaded. To enable this feature your Openshift namespace has to contain secret `tower-promotion-secret` with username and password of Tower user who has permission to run requested Tower job templates.

  Secret creation:

file modified
+5 -1
@@ -9,6 +9,8 @@ 

    - "{{ c3i_component }}"

  

  # Git repo for build

+ # pagure https://pagure.io/{{ c3i_component }}.git

+ # gerrit https://code.engineering.redhat.com/gerrit/{{ c3i_component }}.git

  c3i_git_repo: https://pagure.io/{{ c3i_component }}.git

  # Main branch used for triggering post merge workflow.

  c3i_git_main_branch: master
@@ -43,12 +45,14 @@ 

  c3i_definition_update_script: ansible-playbook deploy.yml -e c3i_skip_service_accounts=true

  

  # Api key for pagure - has to have permissions for: Flag a commit, Comment on a pull-request, Flag a pull-request

- c3i_pagure_api_key_secret: pagure-api-key

+ c3i_pagure_api_key_secret: "{{ 'pagure-api-key' if 'pagure' in c3i_git_repo else '' }}"

  

  # Temporarily disable doc push to workaround https://pagure.io/pagure/issue/3919. Remove this line when it is fixed.

  c3i_pagure_doc_repo_name:

  c3i_pagure_doc_secret: pagure-doc-secret

  

+ # Name of the server created in Jenkin Gerrit trigger plugin

+ c3i_gerrit_server: gerrit

  

  c3i_default_agent_snippet: default-agent.groovy

  c3i_build_agent_snippet: "{{ c3i_default_agent_snippet }}"

@@ -24,43 +24,58 @@ 

      PAGURE_REPO_IS_FORK = "${env.GIT_REPO.contains('/forks/') ? 'true': 'false'}"

    }

    {% if "postmerge" not in job_vars.name %}

-   triggers {

-     ciBuildTrigger(

-       noSquash: true,

-       providerList: [

-         {% if "premerge" in job_vars.name %}

-         {% for topic in job_vars.messaging_fedmsg_topics %}

-         fedmsgSubscriber(

-           name: params.MESSAGING_FEDMSG_PROVIDER,

-           overrides: [topic: "{{ topic }}"],

-           checks: [

-             [field: '$.pullrequest.project.url_path', expectedValue: params.GIT_REPO.split('/')[3..-1].join('/').replace('forks/', 'fork/').replaceAll(/.git$/, '')],

-             [field: '$.pullrequest.branch', expectedValue: params.GIT_MAIN_BRANCH],

-           ]

-         ),

-         {% endfor %}

-         {% elif "job-updater" in job_vars.name %}

-         {% for topic in job_vars.messaging_fedmsg_topics %}

-         fedmsgSubscriber(

-           name: params.MESSAGING_FEDMSG_PROVIDER,

-           overrides: [topic: "{{ topic }}"],

-           checks: [

-             [field: '$.repo.url_path', expectedValue: "^${params.GIT_REPO.split('/')[3..-1].join('/').replace('forks/', 'fork/').replaceAll(/.git$/, '')}\$"],

-             [field: '$.branch', expectedValue: params.GIT_MAIN_BRANCH],

-           ]

-         )

-         {% endfor %}

-         {% endif %}

-       ]

-     )

-   }

+     // pagure

+     {% if "pagure" in c3i_git_repo %}

+     triggers {

+       ciBuildTrigger(

+         noSquash: true,

+         providerList: [

+           {% if "premerge" in job_vars.name %}

+           {% for topic in job_vars.messaging_fedmsg_topics %}

+           fedmsgSubscriber(

+             name: params.MESSAGING_FEDMSG_PROVIDER,

+             overrides: [topic: "{{ topic }}"],

+             checks: [

+               [field: '$.pullrequest.project.url_path', expectedValue: params.GIT_REPO.split('/')[3..-1].join('/').replace('forks/', 'fork/').replaceAll(/.git$/, '')],

+               [field: '$.pullrequest.branch', expectedValue: params.GIT_MAIN_BRANCH],

+             ]

+           ),

+           {% endfor %}

+           {% elif "job-updater" in job_vars.name %}

+           {% for topic in job_vars.messaging_fedmsg_topics %}

+           fedmsgSubscriber(

+             name: params.MESSAGING_FEDMSG_PROVIDER,

+             overrides: [topic: "{{ topic }}"],

+             checks: [

+               [field: '$.repo.url_path', expectedValue: "^${params.GIT_REPO.split('/')[3..-1].join('/').replace('forks/', 'fork/').replaceAll(/.git$/, '')}\$"],

+               [field: '$.branch', expectedValue: params.GIT_MAIN_BRANCH],

+             ]

+           )

+           {% endfor %}

+           {% endif %}

+         ]

+       )

+     }

+     // gerrit trigger

+     {% elif "gerrit" in c3i_git_repo %}

+       triggers {

+         gerrit customUrl: '',

+         gerritProjects:

+           [[branches: [[compareType: 'PLAIN', pattern: params.GIT_MAIN_BRANCH ]],

+           compareType: 'ANT',

+           disableStrictForbiddenFileVerification: false,

+           pattern:  env.GIT_REPO.split('/')[-1].replaceAll(/.git$/, '')]],

+         serverName: env.GERRIT_SERVER_NAME,

+         // there are variables in job-updater.yml and premerge.yml which change the value of trigger

+         triggerOnEvents: [{{ job_vars.gerrit_trigger }}]

+       }

+     {% endif %}

    {% endif %}

    {% if c3i_trigger_update_only %}

    {% include "trigger-update-stages.groovy" %}

    {% else %}

- 

    stages {

-     stage('Proceeding CI_MESSAGE') {

+     stage('Proceeding CI_MESSAGE from UMB') {

        when {

          expression { env.CI_MESSAGE }

        }
@@ -73,7 +88,21 @@ 

          }

        }

      }

-     stage('Update Build Info') {

+     stage('Proceeding Gerrit trigger') {

+       when {

+         expression { env.GERRIT_REFSPEC }

+       }

+       steps {

+         script {

+           // figure out how look the message when it is merged

+           if (env.GERRIT_EVENT_TYPE == "patchset-created") {

+             env.GIT_REPO_REF = env.GERRIT_REFSPEC

+             env.PR_NO = env.GERRIT_CHANGE_NUMBER

+           }

+         }

+       }

+     }

+     stage('Clone git repo') {

        steps {

          script {

            if (!env.GIT_REPO_REF) {
@@ -81,11 +110,17 @@ 

            }

  

            // FIXME: Due to a bug described in https://issues.jenkins-ci.org/browse/JENKINS-45489

-           c3i.clone(repo: params.GIT_REPO,

-             branch: env.GIT_REPO_REF)

+           c3i.clone(repo: params.GIT_REPO, branch: env.GIT_REPO_REF)

            env.GIT_COMMIT = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()

            echo "Build ${env.GIT_REPO_REF}, commit=${env.GIT_COMMIT}"

- 

+         }

+       }

+     }

+     // this is not needed for Gerrit

+     {% if "pagure" in c3i_git_repo %}

+     stage('Update Build Info') {

+       steps {

+         script {

            // Set friendly display name and description

            def pagure_repo_home = env.GIT_REPO.replace('/forks/', '/fork/').replaceAll(/.git$/,'')

            {% if "premerge" in job_vars.name %}
@@ -125,6 +160,10 @@ 

          }

        }

      }

+     {% endif %}

+     // Update jenkins files through oc command

+     // run all jobs from templates/jobs directory

+     // job updater is on the same lever as postmerge/premerge

      {% if "job-updater" in job_vars.name %}

      stage('Update pipeline jobs') {

        steps {
@@ -135,7 +174,7 @@ 

          }

        }

      }

-     stage('Trigger postmerge') {

+     stage('Trigger postmerge - build, test and upload container') {

        steps {

          script {

            openshift.withCluster() {
@@ -181,8 +220,10 @@ 

          }

        }

      }

- 

+     // run component snippet to run and test the component

      {{ task_var_build_and_test }}

+ 

+ 

      stage('Push container') {

        when {

          expression {
@@ -225,6 +266,7 @@ 

      }

      stage('Triggering Tower deployment') {

        when {

+         // env.GIT_REPO_REF == params.GIT_MAIN_BRANCH it means that this is a postmerge

          expression { env.GIT_REPO_REF == params.GIT_MAIN_BRANCH && params.TOWER_TEMPLATE_ID && params.TOWER_SECRET }

        }

        {% include "triggering-tower-steps.groovy" %}

file modified
+10 -8
@@ -13,10 +13,18 @@ 

        env:

        - name: GIT_REPO

          value: {{ c3i_git_repo }}

-       - name: GIT_REPO_REF

-         value: {{ job_vars.git_repo_ref }}

        - name: GIT_MAIN_BRANCH

          value: {{ c3i_git_main_branch }}

+       - name: GIT_REPO_REF

+         value: {{ job_vars.git_repo_ref }}

+       - name: PAGURE_DOC_REPO_NAME

+         value: {{ c3i_pagure_doc_repo_name }}

+       - name: PAGURE_DOC_SECRET

+         value: {{ c3i_pagure_doc_secret }}

+       - name: PAGURE_API_KEY_SECRET_NAME

+         value: {{ c3i_pagure_api_key_secret }}

+       - name: GERRIT_SERVER_NAME

+         value: {{ c3i_gerrit_server }}

        - name: OPENSHIFT_CLOUD_NAME

          value: {{ c3i_cloud_name }}

        - name: JENKINS_AGENT_IMAGE
@@ -29,18 +37,12 @@ 

          value: {{ c3i_container_registry_credentials }}

        - name: IMAGE_TAG

          value: {{ c3i_dev_image_tag }}

-       - name: PAGURE_DOC_REPO_NAME

-         value: {{ c3i_pagure_doc_repo_name }}

-       - name: PAGURE_DOC_SECRET

-         value: {{ c3i_pagure_doc_secret }} 

        - name: MESSAGING_PROVIDER

          value: {{ c3i_messaging_provider }}

        - name: POSTMERGE_JOB

          value: {{ c3i_component }}-postmerge

        - name: MESSAGING_FEDMSG_PROVIDER

          value: {{ c3i_fedmsg_provider }}

-       - name: PAGURE_API_KEY_SECRET_NAME

-         value: {{ c3i_pagure_api_key_secret }}

        - name: MAIL_ADDRESS

          value: {{ c3i_mail_address }}

        - name: C3IAAS_NAMESPACE

@@ -4,3 +4,4 @@ 

  messaging_fedmsg_topics:

    - io.pagure.prod.pagure.git.receive

  git_repo_ref: master

+ gerrit_trigger: changeMerged()

@@ -7,3 +7,4 @@ 

    - io.pagure.prod.pagure.pull-request.reopened

    - io.pagure.prod.pagure.pull-request.rebased

  git_repo_ref:

+ gerrit_trigger: patchsetCreated()

@@ -6,3 +6,4 @@ 

  jms-messaging:latest

  configuration-as-code:latest

  rebuild:latest

+ gerrit-trigger:latest

@@ -10,7 +10,7 @@ 

  c3i_lib_url:

  c3i_lib_branch:

  

- c3i_git_repo:

+ c3i_git_repo: ""

  c3i_git_main_branch:

  

  c3i_jenkins_agent_image: "{{ c3i_workflow_jenkins_image }}"

  • add documentation
  • update c3i role

Build 92c76a5 FAILED!
Rebase or make new commits to rebuild.

rebased onto 7c15e12

4 years ago

Build 7c15e12 FAILED!
Rebase or make new commits to rebuild.

rebased onto d1d6889

4 years ago

Build d1d6889 FAILED!
Rebase or make new commits to rebuild.

rebased onto afa3603

4 years ago

rebased onto d83017a

4 years ago

Build afa3603 FAILED!
Rebase or make new commits to rebuild.

Build d83017a FAILED!
Rebase or make new commits to rebuild.

rebased onto c7b068f

4 years ago

Build c7b068f FAILED!
Rebase or make new commits to rebuild.

rebased onto 08dadde

4 years ago

Build 08dadde FAILED!
Rebase or make new commits to rebuild.

rebased onto fcc5238

4 years ago

Build fcc5238 FAILED!
Rebase or make new commits to rebuild.

rebased onto 037ea79

4 years ago

rebased onto f8b8f82

4 years ago

rebased onto b6a1f92

4 years ago

Pull-Request has been merged by pbortlov

4 years ago

Build f8b8f82 FAILED!
Rebase or make new commits to rebuild.

Build b6a1f92 FAILED!
Rebase or make new commits to rebuild.

Build b6a1f92 FAILED!
Rebase or make new commits to rebuild.