From 1a12f9caf854d471f40a3b0a82f8efa8c8f93f2c Mon Sep 17 00:00:00 2001 From: Michal Kovarik Date: May 18 2020 07:19:06 +0000 Subject: Skip trigger update when there is no change in deploymentConfig --- diff --git a/roles/c3i/defaults/main.yml b/roles/c3i/defaults/main.yml index 17a5021..e8ea494 100644 --- a/roles/c3i/defaults/main.yml +++ b/roles/c3i/defaults/main.yml @@ -99,12 +99,7 @@ c3i_cloud_name: openshift # Jenkins for Jenkinsfile validation - has to have read access for anonymous c3i_jenkins_master_validation: jenkins-c3i.cloud.paas.psi.redhat.com -# Internal variable, overriden in Jenkins jobs with triggers. -# Jobs with triggers are applied in this way: -# 1) Configured to run on master node and stages part is replaced by noop stages part. -# 2) Job is executed and triggers are set on the job. -# 3) Build from noop stages is removed. -# 4) Job is reconfigured with final configuration. +# Internal variable, used in roles/c3i/tasks/trigger-update.yml c3i_trigger_update_only: false # Ansible tower instance diff --git a/roles/c3i/tasks/build.yml b/roles/c3i/tasks/build.yml index ce376ba..81f118f 100644 --- a/roles/c3i/tasks/build.yml +++ b/roles/c3i/tasks/build.yml @@ -63,6 +63,8 @@ include_tasks: trigger-update.yml vars: build_config: "{{ job_vars.name }}" + task_var_build_and_test: "{{ lookup('template', c3i_build_and_test_snippet)}}" + register: trigger_update when: '"-premerge" in job_vars.name and "messaging_fedmsg_topics" in job_vars' - name: Build config {{ job_vars.name }} @@ -72,3 +74,4 @@ definition: "{{ lookup('template', job_vars.template) }}" vars: task_var_build_and_test: "{{ lookup('template', c3i_build_and_test_snippet)}}" + when: trigger_update is skipped diff --git a/roles/c3i/tasks/greenwave-promote-image.yml b/roles/c3i/tasks/greenwave-promote-image.yml index 51eda4c..0d469ac 100644 --- a/roles/c3i/tasks/greenwave-promote-image.yml +++ b/roles/c3i/tasks/greenwave-promote-image.yml @@ -62,9 +62,3 @@ - name: Trigger update for {{ image_name }} include_tasks: trigger-update.yml - -- name: Build config for {{ image_name }} - k8s: - namespace: "{{ c3i_ocp_namespace }}" - state: present - definition: "{{ lookup('template', job_vars.template) }}" diff --git a/roles/c3i/tasks/trigger-on-tag.yml b/roles/c3i/tasks/trigger-on-tag.yml index abae7db..b1f013b 100644 --- a/roles/c3i/tasks/trigger-on-tag.yml +++ b/roles/c3i/tasks/trigger-on-tag.yml @@ -61,11 +61,5 @@ - name: Trigger update for {{ job_vars.name }} include_tasks: trigger-update.yml - -- name: Build config {{ job_vars.name }} - k8s: - namespace: "{{ c3i_ocp_namespace }}" - state: present - definition: "{{ lookup('template', job_vars.template) }}" vars: task_var_integration_test: "{{ lookup('template', c3i_integration_test_snippet) }}" diff --git a/roles/c3i/tasks/trigger-update.yml b/roles/c3i/tasks/trigger-update.yml index 098bb7e..bb10b44 100644 --- a/roles/c3i/tasks/trigger-update.yml +++ b/roles/c3i/tasks/trigger-update.yml @@ -1,17 +1,37 @@ - set_fact: job_vars_name: "{{ job_vars.name | default(image_name) }}" -- name: Build config for trigger update for {{ job_vars_name }} +- name: "{{ job_vars_name }}: Check BuildConfig change" k8s: namespace: "{{ c3i_ocp_namespace }}" state: present definition: "{{ lookup('template', job_vars.template) }}" - vars: - c3i_trigger_update_only: true + register: build_update -- name: Update triggers for {{ job_vars_name }} - shell: "oc start-build --wait -n {{ c3i_ocp_namespace }} {{ job_vars_name }}" - register: result +# Reconfiguration of Jenkins job to set Trigger section properly: +# 1) Configure Jenkins Job to run on master node and stages part is replaced by noop stages part. +# 2) Jenkins Job is executed and triggers are set on the job. +# 3) Build run from noop stages is removed. +# 4) Jenkins Job is reconfigured with final configuration. +- block: + - name: "{{ job_vars_name }}: Update BuildConfig to be run on master and without stages" + k8s: + namespace: "{{ c3i_ocp_namespace }}" + state: present + definition: "{{ lookup('template', job_vars.template) }}" + vars: + c3i_trigger_update_only: true -- name: Delete triggers update build for {{ job_vars_name }} - shell: "oc -n {{ c3i_ocp_namespace }} delete {{ result.stdout_lines[0].split()[0] }}" + - name: "{{ job_vars_name }}: Run BuildConfig to enable triggers" + shell: "oc start-build --wait -n {{ c3i_ocp_namespace }} {{ job_vars_name }}" + register: result + + - name: "{{ job_vars_name }}: Delete generated build from the previous step" + shell: "oc -n {{ c3i_ocp_namespace }} delete {{ result.stdout_lines[0].split()[0] }}" + + - name: "{{ job_vars_name }}: Recover original BuildConfig" + k8s: + namespace: "{{ c3i_ocp_namespace }}" + state: present + definition: "{{ lookup('template', job_vars.template) }}" + when: build_update.changed