Jenkins Script Decomposition

2022年6月29日 2220点热度 2人点赞 0条评论
内容目录

Overall Format

General format definition

pipeline {

    // Global environment variables
    // environment {
    //     IMAGENAME     = 'webdemo'       // Image name
    // }

    // Parameters visible on Jenkins
    // parameters{
    //     string(name: 'REPO_NAME' ,defaultValue:'',description:'Repository name',trim:true)
    // }

    agent {
        // How to start the build environment, Linux, Windows nodes, or start a container
        docker {
            // label 'linux'   Select a node machine to execute the script
            image 'mcr.microsoft.com/dotnet/sdk:5.0' 
            // Map some host files to the container
            args '-u root -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker  -v /root/.ssh:/root/.ssh'
            reuseNode  true
        }
    }
    stages {

        // Steps
        stage('Check1'){
        // Script code
        }

        stage('Check2'){
        // Script code
        }
    }
}

Template Variable Replacement Script

Define template:

kind: Deployment
apiVersion: apps/v1
metadata:
  name: ${APPNAME}
  namespace: ${NAMESPACE}
  labels:
    app: ${APPNAME}
spec:
  replicas: 1
  selector:
  ... ...

Replace the ${} variables:

eval "cat <<EOF
$(< deploy.yaml)
"  > newdeploy.yaml

File to environment variables:

# Namespace
NAMESPACE=dev
# Application name
APPNAME=yzf-web1
# Application ID under dapr
DAPR_APPID=yzf-web1
# Web application port
APPPORT=5000
                    # Get custom variable configurations into the system environment
                    source ./deploy_env.conf

痴者工良

高级程序员劝退师

文章评论