jenkins-x, kubernetes

Jenkins-X 3 – Add steps to a docker pipeline catalog

Jenkins-X 3 – Add steps to a docker pipeline catalog

We are using the Docker pipeline catalog for one of our application where it only builds an image and does not deploy an application. We need to run our test script so we needed to add more steps to the pipeline.

We use this template:

https://github.com/jenkins-x/jx3-pipeline-catalog/blob/master/tasks/docker/pullrequest.yaml

Overview

Our react application is deployed as a Docker image as we only need its static contents and deploy it on an nginx server along with other static contents. We noticed that it didn’t actually run our test scripts as it is not part of the pipeline catalog steps. Therefore, we added a few steps into the pull request and release template.

Here is our original lighthouse config for pull requests.

# .lighthouse/jenkins-x/pullrequest.yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  creationTimestamp: null
  name: pullrequest
spec:
  pipelineSpec:
    tasks:
    - name: from-build-pack
      resources: {}
      taskSpec:
        metadata: {}
        stepTemplate:
          image: uses:jenkins-x/jx3-pipeline-catalog/tasks/docker/pullrequest.yaml@versionStream
          name: ""
          resources:
            # override limits for all containers here
            limits: {}
          workingDir: /workspace/source
        steps:
        - image: uses:jenkins-x/jx3-pipeline-catalog/tasks/git-clone/git-clone-pr.yaml@versionStream
          name: ""
          resources: {}
        - name: jx-variables
          resources:
            requests:
              cpu: 400m
              memory: 512Mi
        - name: check-registry
          resources: {}
        - name: build-container-build
          resources: {}
  podTemplate: {}
  serviceAccountName: tekton-bot
  timeout: 12h0m0s
status: {}

Additional Steps

Looking at the list of pipeline catalog tasks, we found that the “javascript” template is what we need as it has the npm test into it. We simply added to following to the config file.

- image: node:14-slim
  name: build-npm-install
  resources: {}
  script: |
    #!/bin/sh
    npm install
- image: node:14-slim
  name: build-npm-test
  resources: {}
  script: |
    #!/bin/sh
    CI=true DISPLAY=:99 npm test

Final Configuration

Below is out final configuration for the pull request. Same changes applies to the release.yaml template.

# .lighthouse/jenkins-x/pullrequest.yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  creationTimestamp: null
  name: pullrequest
spec:
  pipelineSpec:
    tasks:
    - name: from-build-pack
      resources: {}
      taskSpec:
        metadata: {}
        stepTemplate:
          image: uses:jenkins-x/jx3-pipeline-catalog/tasks/docker/pullrequest.yaml@versionStream
          name: ""
          resources:
            # override limits for all containers here
            limits: {}
          workingDir: /workspace/source
        steps:
        - image: uses:jenkins-x/jx3-pipeline-catalog/tasks/git-clone/git-clone-pr.yaml@versionStream
          name: ""
          resources: {}
        - name: jx-variables
          resources:
            requests:
              cpu: 400m
              memory: 512Mi
        - image: node:14-slim
          name: build-npm-install
          resources: {}
          script: |
            #!/bin/sh
            npm install
        - image: node:14-slim
          name: build-npm-test
          resources: {}
          script: |
            #!/bin/sh
            CI=true DISPLAY=:99 npm test
        - name: check-registry
          resources: {}
        - name: build-container-build
          resources: {}
  podTemplate: {}
  serviceAccountName: tekton-bot
  timeout: 12h0m0s
status: {}

Now our build process runs the test cases for our react application.

Featured image: ThisIsEngineering