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.
-
You have created an application in Konflux
-
You have the url of the jenkins instance and the name of the job you want to trigger.
-
You have a jenkins username and jenkins API token that can be used to initiate jobs in your jenkins instance.
-
Your jenkins job has a parameter that allows you to specify the artifact from konflux.
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:
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)
Follow the instructions in the creating secrets guide, with the following details:
-
For Secret name, enter
my-jenkins-credentials
. -
Under Key/value secret, expand Key/value 1, then enter the key name
username
. Supply the jenkins username in the field. -
Under Key/value secret, expand Key/value 2, then enter the key name
apitoken
. Paste the API token into the field.
Follow the instructions in the adding an integration test guide, with the following details:
-
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. -
In the Path in repository field, enter
pipelines/jenkins.yaml
, which refers to the pipeline you created in the previous section. -
Expand the Parameters field.
-
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. -
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.
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:
-
Go to the Integration tests tab and select the highlighted name of your test.
-
Go to the Pipeline runs tab of that test and select the most recent run.
-
You should be able to find the jenkins URLs in the logs.
-
Edit the integration test if it is not properly configured.