1
0
mirror of https://github.com/tektoncd/catalog.git synced 2024-11-22 06:02:51 +00:00
catalog/task/trigger-jenkins-job/0.1
PuneetPunamiya 5a3e5f630f Adds category field as an annotation as tekton.dev/categories
- Initially all tags were mapped to categories in Hub,
     for e.g. config.yaml: https://github.com/tektoncd/hub/blob/master/config.yaml,
     so whenever a new tag was added in a task it was mapped to a category called `others`.
     Hence before every release we had to manually map these new tags to some category,
     hence after the discussion in Catalog and Hub WG, a proposal was created for adding
     a category as an annotation.

   - PR to update the TEP-0003-Tekton Catalog Organization: https://github.com/tektoncd/community/pull/352

Signed-off-by: Puneet Punamiya <ppunamiy@redhat.com>
2021-07-26 13:15:08 +01:00
..
samples Add Task to Trigger Jenkins Pipeline using Tekton 2020-07-29 16:24:02 +01:00
tests Fix jenkins and trigger-jenkins-job task tests 2021-02-15 10:57:46 +00:00
README.md Update self reference from master to main 🧙 2021-03-19 11:09:49 +00:00
trigger-jenkins-job.yaml Adds category field as an annotation as tekton.dev/categories 2021-07-26 13:15:08 +01:00

Trigger Jenkins Job

The following task can be used to trigger a Jenkins job using CURL request from a Tekton Task.

More details on Remote Access API can be found here

Install the Task

kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/main/task/trigger-jenkins-job/0.1/trigger-jenkins-job.yaml

Parameters

  • JENKINS_HOST_URL: The URL on which Jenkins is running (Required)

  • JOB_NAME: The Job name which needs to be triggered (Required)

  • JENKINS_SECRETS: The name of the secret containing the username and API token for authenticating the Jenkins (Default: jenkins-credentials) (Required)

  • JOB_PARAMS: Extra parameters which needs to be appended in the CURL request. (Default: ""). JOB_PARAMS is of type array so multiple arguments can be appended. JOB_PARAMS can be provided as follows:-

    params:
      - name: JOB_PARAMS
        value: |
          - FILE_LOCATION_AS_SET_IN_JENKINS=@PATH_TO_FILE      
    

Workspaces

  • source: In case any file needs to be provided to the Jenkins Job. (Default: emptyDir: {})

Secrets

Secrets containing username,API token and crumb that are used in the task for making the CURL request.

Crumb can be obtained using following command :-

$ wget -q --auth-no-challenge --user username --password password --output-document - 'http://${Jenkins_URL}/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'

This will give you something like Jenkins-Crumb:44e7033af70da95a47403c3bed5c10f8. Without crumb information, running curl command will result in example errors such as HTTP/1.1 403 Forbidden or Error 403 No valid crumb was included in the request.

apiVersion: v1
kind: Secret
metadata:
  name: jenkins-credentials
type: Opaque
stringData:
  username: username
  apitoken: api-token
  crumb: crumb

Usage

  1. Without JOB_PARAMS parameters

    apiVersion: tekton.dev/v1beta1
    kind: TaskRun
    metadata:
      name: trigger-jenkins-job-run
    spec:
      taskRef:
        name: trigger-jenkins-job
      params:
        - name: JENKINS_HOST_URL
          value: "http://localhost:8080"
        - name: JOB_NAME
          value: tekton
      workspaces:
        - name: source
          emptyDir: {}
    
  2. With JOB_PARAMS parameters

    apiVersion: tekton.dev/v1beta1
    kind: TaskRun
    metadata:
      name: trigger-jenkins-job-run
    spec:
      taskRef:
        name: trigger-jenkins-job
      params:
        - name: JENKINS_HOST_URL
          value: "http://localhost:8080"
        - name: JOB_NAME
          value: tekton
        - name: JOB_PARAMS
          value:
            - id=123
            - verbosity=high
      workspaces:
        - name: source
          emptyDir: {}