Automate with Jenkins

Automate Updatecli with Jenkins

Description

Updatecli is better when executed regularly so let see how Jenkins becomes handy.

Example

The current example is inspired from the repository jenkins-infra/charts.

Requirement:

  • It assumes using Jenkins with agent running on kubernetes using the kubernetes-plugin.

  • It also assumes having access to credentials needed by your updatecli configurations which is "updatecli-github-token" in this case.

The Jenkins agent uses the updatecli docker image to execute every 30min updatecli. It applies every configurations found under the directory "./updateCli/updateCli.d" using parameters provided by "./updateCli/values.yaml".

Jenkinsfile
pipeline {
  agent {
    kubernetes {
      label 'updatecli'
      yamlFile 'PodTemplates.yaml'
    }
  }
  environment {
    UPDATECLI_GITHUB_TOKEN  = credentials('updatecli-github-token')
  }

  triggers {
    cron 'H/30 * * * *'
  }

  stages {
    stage('Check Configuration Update') {
      steps {
        container('updatecli') {
          sh 'updatecli diff --config ./updateCli/updateCli.d --values ./updateCli/values.yaml'
        }
      }
    }
    stage('Apply Configuration Update') {
      steps {
        container('updatecli') {
          sh 'updatecli apply --config ./updateCli/updateCli.d --values ./updateCli/values.yaml'
        }
      }
    }
  }
PodTemplates.yaml
apiVersion: "v1"
kind: "Pod"
metadata:
  labels:
    jenkins: "agent"
    job: "updatecli"
spec:
  containers:
  - args:
    - "99d"
    command:
    - "sleep"
    image: "ghcr.io/updatecli/updatecli:latest"
    imagePullPolicy: "Always"
    name: "updatecli"
    resources:
      limits:
        memory: "512Mi"
        cpu: "400m"
      requests:
        memory: "512Mi"
        cpu: "400m"
    securityContext:
      privileged: false
    tty: true
  restartPolicy: "Never"

Edit this page on GitHub