Automate with Jenkins

Automate Updatecli with Jenkins

Description

Updatecli is most effective when executed regularly and automatically.

Example

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

Requirement

  • We assume using Jenkins with agent running from kubernetes using the kubernetes-plugin.

  • We assume 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 updatecli every 30 minutes. It applies the configurations found under the directory "./updateCli/updateCli.d" using the parameters in "./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"
Top