Jenkins

In this guide, you’ll learn how to add a custom integration test in Konflux that triggers a jenkins job in a jenkins instance outside of konflux using the jenkins remote access API.

Prerequisites
  1. You have created an application in Konflux

  2. You have the url of the jenkins instance and the name of the job you want to trigger.

  3. You have a jenkins username and jenkins API token that can be used to initiate jobs in your jenkins instance.

  4. Your jenkins job has a parameter that allows you to specify the artifact from konflux.

Procedure

You need to perform three major steps. Write your trigger pipeline using a shared task, upload your Jenkins API credentials to Konflux, and register an Integration test with Konflux to send requests to the Jenkins API. Complete the following steps in the Konflux console:

Procedure - Writing the test pipeline

We’ll make use of a shared trigger jenkins job task.

Similar to the instructions in the creating an integration test guide, commit the following Pipeline definition to a file named pipelines/jenkins.yaml in a repository under your control, like https://github.com/your-org/your-tests-repo.

+

kind: Pipeline
apiVersion: tekton.dev/v1beta1
metadata:
  name: my-jenkins-trigger
spec:
  params:
    - name: JENKINS_HOST_URL
      type: string
    - name: JOB_NAME
      type: string
    - description: 'Snapshot of the konflux application'
      name: SNAPSHOT
      type: string
  tasks:
    - name: trigger-jenkins-job
      taskRef:
        resolver: "git"
        params:
        - name: url
          value: https://github.com/konflux-ci/tekton-integration-catalog.git
        - name: revision
          value: main
        - name: pathInRepo
          value: tasks/triggers/jenkins/0.1/trigger-jenkins-job.yaml
      params:
        - name: JENKINS_HOST_URL
          value: $(params.JENKINS_HOST_URL)
        - name: JOB_NAME
          value: $(params.JOB_NAME)
	- name: JENKINS_SECRETS
	  value: my-jenkins-credentials
	- name: JOB_PARAMS
	  value: |
	  - KONFLUX_SNAPSHOT=$(params.SNAPSHOT)
Procedure - Upload your Jenkins API key

Follow the instructions in the creating secrets guide, with the following details:

  1. For Secret name, enter my-jenkins-credentials.

  2. Under Key/value secret, expand Key/value 1, then enter the key name username. Supply the jenkins username in the field.

  3. Under Key/value secret, expand Key/value 2, then enter the key name apitoken. Paste the API token into the field.

Procedure - Registering the Integration Test

Follow the instructions in the adding an integration test guide, with the following details:

  1. In the GitHub URL field, enter https://github.com/your-org/your-tests-repo, which is a git repository containing a tekton pipeline and task that can send requests to the Testing Farm API.

  2. In the Path in repository field, enter pipelines/jenkins.yaml, which refers to the pipeline you created in the previous section.

  3. Expand the Parameters field.

  4. Select Add parameter. For the Name field, enter JENKINS_HOST_URL. For the Value field, enter the url to the jenkins instance you want to trigger.

  5. Select Add parameter. For the Name field, enter JOB_NAME. For the Value field, enter the url to the jenkins job you want to trigger.

Verification

To start building a new component, either open a new pull request (PR) that targets the tracked branch of the component in the GitHub repository, or comment '/retest' on an existing PR.

When the new build is finished:

  1. Go to the Integration tests tab and select the highlighted name of your test.

  2. Go to the Pipeline runs tab of that test and select the most recent run.

  3. You should be able to find the jenkins URLs in the logs.

  4. Edit the integration test if it is not properly configured.