Kahibaro
Discord Login Register

Integrating OpenShift with external CI tools

Integration patterns and architecture

External CI tools (Jenkins, GitHub Actions, GitLab CI, Azure DevOps, etc.) typically integrate with OpenShift through a small set of patterns:

When choosing a pattern consider:

Accessing OpenShift from external CI

Authentication options

External CI needs credentials to call the OpenShift API or run oc:

    oc create sa ci-deployer -n my-app
    oc adm policy add-role-to-user edit -z ci-deployer -n my-app
    oc sa get-token ci-deployer -n my-app

Network and security considerations

Using `oc` in external CI pipelines

Many integrations rely on oc rather than direct REST calls.

Installing and configuring `oc` in CI

    deploy:
      image: registry.redhat.io/openshift4/ose-cli
      stage: deploy
      script:
        - oc login "$OCP_API_URL" --token="$OCP_TOKEN" --insecure-skip-tls-verify=false
        - oc project my-app
        - oc rollout restart deployment/my-app
    curl -L "$OC_DOWNLOAD_URL" | tar -xz
    sudo mv oc /usr/local/bin

Common deployment actions from CI

Once authenticated, typical CI actions include:

  oc project my-app
  oc set image deployment/my-app \
    my-app-container=quay.io/myorg/my-app:${CI_COMMIT_SHA}
  oc apply -f k8s/
  oc rollout restart deployment/my-app
  oc rollout status deployment/my-app --timeout=120s

Image registry integration patterns

External CI builds, OpenShift only deploys

Typical for GitHub Actions, GitLab CI, Jenkins:

  1. CI builds image (Docker/Buildah/kaniko).
  2. CI pushes to registry (Quay.io, Docker Hub, GitLab registry, etc.).
  3. OpenShift pulls the image for deployment.

Key points:

  oc create secret docker-registry external-regcred \
    --docker-server=registry.example.com \
    --docker-username="$REG_USER" \
    --docker-password="$REG_PASS" \
    --docker-email=dev@example.com \
    -n my-app
  oc secrets link default external-regcred --for=pull -n my-app

Using OpenShift internal registry from external CI

Jenkins and OpenShift

Jenkins is a common external CI tool in OpenShift environments.

Integration models

Example Jenkins pipeline snippet

pipeline {
  agent any
  environment {
    OCP_API_URL = 'https://api.my-cluster.example.com:6443'
    OCP_TOKEN   = credentials('ocp-ci-token')  // Jenkins credential ID
    OCP_PROJECT = 'my-app'
  }
  stages {
    stage('Login to OpenShift') {
      steps {
        sh """
          oc login ${OCP_API_URL} \
            --token=${OCP_TOKEN} \
            --insecure-skip-tls-verify=false
          oc project ${OCP_PROJECT}
        """
      }
    }
    stage('Deploy') {
      steps {
        sh """
          oc set image deployment/my-app \
            my-app-container=quay.io/myorg/my-app:${GIT_COMMIT}
          oc rollout status deployment/my-app --timeout=120s
        """
      }
    }
  }
}

GitHub Actions and OpenShift

GitHub Actions commonly integrates using oc plus an external registry.

Typical workflow

  1. Build and push the image:
   - name: Build and push image
     uses: docker/build-push-action@v6
     with:
       context: .
       push: true
       tags: quay.io/myorg/my-app:${{ github.sha }}
  1. Deploy to OpenShift using oc:
   - name: Install oc
     run: |
       curl -L "$OC_DOWNLOAD_URL" | tar -xz
       sudo mv oc /usr/local/bin
   - name: Login to OpenShift
     run: |
       oc login ${{ secrets.OCP_API_URL }} \
         --token=${{ secrets.OCP_TOKEN }} \
         --insecure-skip-tls-verify=false
       oc project my-app
   - name: Update deployment
     run: |
       oc set image deployment/my-app \
         my-app-container=quay.io/myorg/my-app:${{ github.sha }}
       oc rollout status deployment/my-app --timeout=120s

GitHub Environments and approvals

GitLab CI and OpenShift

GitLab CI integrates similarly, often with GitLab’s container registry.

Example `.gitlab-ci.yml` snippet

stages:
  - build
  - deploy
variables:
  IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
build:
  stage: build
  image: docker:24
  services:
    - docker:24-dind
  script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
    - docker build -t "$IMAGE_TAG" .
    - docker push "$IMAGE_TAG"
deploy:
  stage: deploy
  image: registry.redhat.io/openshift4/ose-cli
  environment:
    name: production
  script:
    - oc login "$OCP_API_URL" --token="$OCP_TOKEN" --insecure-skip-tls-verify=false
    - oc project my-app
    - oc set image deployment/my-app my-app-container="$IMAGE_TAG"
    - oc rollout status deployment/my-app --timeout=120s
  only:
    - main

Azure DevOps, CircleCI, and other CI systems

The same building blocks apply across CI vendors:

Example Azure DevOps outline

  container: registry.redhat.io/openshift4/ose-cli

Example CircleCI snippet

version: 2.1
jobs:
  deploy:
    docker:
      - image: registry.redhat.io/openshift4/ose-cli
    steps:
      - checkout
      - run:
          name: Login to OpenShift
          command: |
            oc login "$OCP_API_URL" --token="$OCP_TOKEN"
      - run:
          name: Deploy
          command: |
            oc apply -f k8s/
            oc rollout status deployment/my-app --timeout=120s
workflows:
  deploy_workflow:
    jobs:
      - deploy

Integrating external CI with OpenShift Pipelines and GitOps

External CI doesn’t have to drive deployments directly; it can instead trigger OpenShift-native deployment mechanisms.

Triggering OpenShift Pipelines (Tekton) from external CI

Possible patterns:

  oc apply -f pipelinerun.yaml

Advantages:

External CI with GitOps (Argo CD, etc.)

Typical GitOps integration pattern:

  1. External CI:
    • Builds and pushes image.
    • Updates image tag or manifest in a Git repo (e.g., update kustomization.yaml or Helm values.yaml).
    • Commits and pushes changes.
  2. Argo CD (running in OpenShift):
    • Detects Git changes.
    • Syncs manifests to the cluster.

Example: update image tag in a GitOps repo from CI:

- name: Update image tag
  run: |
    sed -i "s|image: .*$|image: quay.io/myorg/my-app:${GIT_COMMIT}|" k8s/deployment.yaml
    git config user.email "ci@example.com"
    git config user.name "CI Bot"
    git commit -am "Update image to ${GIT_COMMIT}"
    git push origin main

This pattern:

Designing robust OpenShift–CI workflows

When stitching external CI to OpenShift, consider:

    curl -f https://my-app.example.com/healthz
    oc annotate deployment/my-app \
      ci.build-url="$CI_JOB_URL" \
      ci.commit="$CI_COMMIT_SHA" \
      --overwrite

Common pitfalls and mitigation

By combining these patterns, you can integrate nearly any external CI system with OpenShift in a secure, maintainable, and auditable way, while still leveraging OpenShift’s native deployment and platform capabilities.

Views: 9

Comments

Please login to add a comment.

Don't have an account? Register now!