簡體   English   中英

如何在 Jenkins 文件(管道)中使用共享庫中的 groovy 常量?

[英]How to use groovy constant from Shared Libray in Jenkins file (pipeline)?

我想在我的 Jenkins 管道中使用來自 Shared Libray 的 grrovy 常量。 我試試這個,但我有這個錯誤:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 27: Not a valid stage section definition: "def paramChecker = ParameterChecker.new(this)". Some extra configuration is required. @ line 27, column 9. stage('Checkout') {

def libIdentifier = "project-jenkins-pipeline"
def libGitBranch = params.LIB_GIT_BRANCH
if(libGitBranch) {
    libIdentifier += "@${libGitBranch}"
}

def com = library(identifier: libIdentifier, changelog: false).com

def Constants = com.project.Constants
def ParameterChecker = com.project.ParameterChecker

pipeline {
    agent {
        docker {
            label "linux"
            image "my-host:8082/project-build-java:jdk1.6-jdk1.8-mvn3.2.5"
            registryUrl 'http://my-host:8082'
            registryCredentialsId 'ReadNexusAccountService'
        }
    }
    stages {
        stage('Clean workspace') {
            steps {
                deleteDir()
            }
        }
        stage('Checkout') {
            def paramChecker = ParameterChecker.new(this)
            paramChecker.checkProjectAndBranchNames()
            checkoutGitSCM(
                url: "${Constants.BITBUCKET_URL}/${paramChecker.projectName}.git",
                tag: Constants.GIT_PROJECT_DEFAULT_BRANCH
            )
        }       
        stage('Compilation Maven') {
            steps {
                timestamps {
                    sh 'mvn -version'   
                }
            }
        }
    }
}

我在階段的steps中有script stage('Checkout')

def libIdentifier = "project-jenkins-pipeline"
def libGitBranch = params.LIB_GIT_BRANCH
if(libGitBranch) {
    libIdentifier += "@${libGitBranch}"
}

def com = library(identifier: libIdentifier, changelog: false).com

pipeline {
    agent {
        docker {
            label "linux"
            image "my-host:8082/project-build-java:jdk1.6-jdk1.8-mvn3.2.5"
            registryUrl 'http://my-host:8082'
            registryCredentialsId 'ReadNexusAccountService'
        }
    }
    stages {
        stage('Clean workspace') {
            steps {
                deleteDir()
            }
        }
        stage('Checkout') {
            steps {
                script {
                    def Constants = com.project.Constants
                    def ParameterChecker = com.project.ParameterChecker
                    def paramChecker = ParameterChecker.new(this)
                    paramChecker.checkProjectAndBranchNames()
                    checkoutGitSCM(
                        url: "${Constants.BITBUCKET_URL}/${paramChecker.projectName}.git",
                        tag: Constants.GIT_PROJECT_DEFAULT_BRANCH
                    )
                }
            }
        }       
        stage('Compilation Maven') {
            steps {
                timestamps {
                    sh 'mvn -version'   
                }
            }
        }
    }
}

感謝@Matt SchuchardJenkins:無法在管道階段定義變量

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM