jenkins - 如何在 Jenkins 文件(管道)中使用 Shared Libray 中的 groovy 常量?
问题描述
我想在我的 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'
}
}
}
}
}
解决方案
我script
进去steps
了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'
}
}
}
}
}
推荐阅读
- rx-java - flatmap 与 RxJava 中的 foreach 相比不起作用
- javascript - 将小时数添加到 new Date().toLocaleTimeString
- swift - 如何处理来自可能包含数组或字典的 API 的响应?
- arrays - 值匹配时不返回 true
- go - 将 x509 certPool 转换为 pemBytes
- python - 当我执行这段简单的代码时获得不同的执行顺序。为什么会这样?
- java - apache http客户端:请求没有被重定向
- python - cx_Oracle 连接超时
- php - @include 刀片存储在数据库中
- android-studio - 无法使用 'cmd package install-create -r -t --full -S' 创建安装会话