Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate job run parameters #254

Merged

Conversation

vfreex
Copy link

@vfreex vfreex commented Aug 24, 2018

Triggering a job run from Jenkins UI or triggers defined in the job
could cause duplicate parameters. This is caused by missing checks
between the build strategy parameters and user specified parameters.

Using LinkedHashMap instread of ArrayList for parameters can
solve this issue, where the user specified parameters are able to overrides those defined in the build strategy silently.

Reproduction:
Create a BuildConfig on OpenShift with JenkinsPipelineBuildStrategy, define an environment variable NAME. Note there is a cron trigger that triggers this job every 3 minutes.

kind: "BuildConfig"
apiVersion: "v1"
metadata:
  name: "demo-pipeline"
spec:
  strategy:
    jenkinsPipelineStrategy:
      env:
      - name: "NAME"
        value: "openshift"
      jenkinsfile: |-
        pipeline {
          agent {
            kubernetes {
              cloud 'openshift'
              label "jenkins-slave-${UUID.randomUUID().toString()}"
              yaml """
              apiVersion: v1
              kind: Pod
              metadata:
                labels:
                  app: "my-jenkins-slave"
              spec:
                containers:
                - name: jnlp
                  image: docker.io/openshift/jenkins-slave-base-centos7:latest
                  tty: true
                  resources:
                    requests:
                      memory: 512Mi
                      cpu: 200m
              """
            }
          }
          triggers { cron('*/3 * * * *') }
          stages {
            stage('foo') {
              steps {
                echo "Hello, ${params.NAME}"
              }
            }
          }
        }

Then start a job run with oc start-build demo-pipeline to let Jenkins Sync plugin create a Jenkins job.
Next, start a job run from Jenkins UI, or wait for a new job run started by the cron trigger. You should see there are 2 duplicate parameters with the same name.

@openshift-ci-robot openshift-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 24, 2018
@vfreex
Copy link
Author

vfreex commented Aug 24, 2018

A bug is reported to Red Hat Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1622014

Triggering a job run from Jenkins UI or triggers defined in the job
could cause duplicate parameters. This is caused by missing checks
between the build strategy parameters with user specified ones.

Using LinkedHashMap instread of ArrayList for parameters can
solve this issue.
@gabemontero
Copy link

/ok-to-test

@openshift-ci-robot openshift-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 24, 2018
@gabemontero gabemontero self-assigned this Aug 24, 2018
@gabemontero
Copy link

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 27, 2018
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gabemontero, vfreex

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 27, 2018
@gabemontero
Copy link

thanks @vfreex !

@openshift-merge-robot openshift-merge-robot merged commit 5f5ce0c into openshift:master Aug 27, 2018
@gabemontero
Copy link

v 1.0.26 of the sync plugin has been initiated

akram pushed a commit to akram/jenkins-sync-plugin that referenced this pull request Aug 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants