Jenkins Pipeline

42 阅读1分钟
DEMO
pipeline {
    agent any // agent { label "label" }
    
    options {
        // lock xx
    }
    
    environment {
        
    }
    
    parameters {
        string(name:"xx", description: "xx", defaultValue: 'xx', trim: true)
        booleanParam(name:"xx", description: "xx", defaultValue: true)
        text(name:"xx", description: "xx", defaultValue: 'xx')
        stashedFile(name:"xx", description: "xx")   
    }
    
    stages {
        stage("name") {
            options {
                // 时间戳
                timestamps()
            }
            steps {
                script {
                    parallel (
                        "stage_1": {

                        },
                        "stage_2": {

                        }
                    )
                }
            }
        }
        
        stage("name") {
            options {
                timestamps()
            }
            steps {
                script {
                    stage {
                        script {
                            ...
                        }
                    }
                }
            }
        }
    }
    post {
        always {
            script {
                timestamps {
                    
                }
                cleanWs()
            }
        }
    }
}

def start_time = new Date(currentBuild.startTimeInMillis).format("yyyy-MM-dd HH:mm:ss", TimeZone.getTimeZone("Asia/Shanghai"))

// file
def response = httpRequest(
        url: url,
        httpMode: mode,
        uploadFile: file_path,
        multipartName: 'file',
        contentType: 'APPLICATION_OCTETSTREAM',
        acceptType: 'APPLICATION_JSON',
        consoleLogResponseBody: true,
        customHeaders: [[name: 'accept', value: 'application/json']]
    )
 // 
 def response = httpRequest(
        url: url,
        httpMode: mode,
        contentType: 'APPLICATION_JSON',
        acceptType: 'APPLICATION_JSON',
        consoleLogResponseBody: true,
        requestBody: body,
        customHeaders: [[name: 'accept', value: 'application/json']]
    )
    
 unstash "file_param"
 mv file_param path/xx