#68 Skip trigger update when there is no change in deploymentConfig
Merged 4 years ago by mkovarik. Opened 4 years ago by mkovarik.
mkovarik/c3i-library skip_trigger  into  master

file modified
+1 -6
@@ -99,12 +99,7 @@ 

  # 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

@@ -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

@@ -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) }}"

@@ -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) }}"

@@ -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

no initial comment

rebased onto d2872b788d070c7654929bd7a25bb84263ef27c1

4 years ago

this is a same name as at line 6. it seems that it even does the same

this is a same name as at line 6. it seems that it even does the same

Yes, it does the same, since first is BuildConfig applied, when it's not changed then it's fine and the block with trigger update is not executed. In case that BuildConfig is changed then it's updated with trigger only configuration, executed to apply changes in trigger and updated again to original version.

rebased onto 3c7969f7bcca3a6ec76ad7ac476ea3b554b10872

4 years ago

Update build config On jenkins master

it needs delete Jenkins build which update only triggers

rebased onto 1179363377ce20da842556f623efe5b3db4f1d52

4 years ago

Doesn't make sense. a build update there is not neccesary to have build for {{ }}

a trigger update otherwise it is a verb

rebased onto d597312f8b8a534f037dde8623a731c88449fa60

4 years ago

one comment otherewise LGTM

rebased onto 1a12f9c

4 years ago

Pull-Request has been merged by mkovarik

4 years ago

Build 1a12f9c FAILED!
Rebase or make new commits to rebuild.