Jenkins

From ismdeep
Jump to navigation Jump to search

Jenkins is an open source automation server. It helps automate the parts of software development related to building, testing and deploying, facilitating continuous integration and continuous delivery.

Official Site: https://www.jenkins.io/ [1]

version: '3.9'

services:
  jenkins:
    image: hub.deepin.com/library/jenkins:lts
    user: root
    environment:
      JAVA_OPTS: "-Duser.timezone=Asia/Shanghai"
    volumes:
      - <data-path>:/var/jenkins_home
    ports:
      - "<export-port>:8080"
    restart: always


pipeline {
    agent any

    stages {
        stage('Clone') {
            steps {
                dir (BUILD_NUMBER) {
                    checkout([
                        $class: 'GitSCM',
                        branches: [[name: "${env.branch}"]],
                        doGenerateSubmoduleConfigurations: false,
                        extensions: [[$class: 'SubmoduleOption',
                            disableSubmodules: false,
                            parentCredentials: true,
                            recursiveSubmodules: true,
                            reference: '',
                            trackingSubmodules: false]],
                        submoduleCfg: [],
                        userRemoteConfigs: [[
                            credentialsId: 'github_auth',
                            url: 'https://github.com/xxxx/xxxxx.git'
                        ]]
                    ])
                }
            }
        }
        stage('Load Config') {
            steps {
                dir (BUILD_NUMBER) {
                    sh 'make load-unittest-config'
                }
            }
        }

        stage('Test') {
            steps {
                dir (BUILD_NUMBER) {
                    sh 'make test'
                }
            }
        }
    }

    post {
        cleanup {
            dir(BUILD_NUMBER) {
                withCredentials([file(credentialsId: 'k8s-config', variable: 'k8s_config')]) {
                    writeFile file: 'k8s-config', text: readFile(k8s_config)
                }
                sh 'curl -LO https://data.ismdeep.com/k8s-cluster-clean.bash'
                sh 'bash k8s-cluster-clean.bash ./k8s-config'
            }
            sh "rm -rf ${BUILD_NUMBER}"
            sh "rm -rf ${BUILD_NUMBER}@tmp"
        }
    }
}

References