尝试在我的Jenkins服务器中实现共享库时遇到问题。
我遇到的错误与以下内容有关
No such DSL method 'agent' found among steps
我尝试删除代理并仅在节点上运行,但仍然存在问题。 我正在关注以下内容:https://jenkins.io/blog/2017/09/25/declarative-1/
有人可以指出我要去哪里了
vars / jenkinsJob.groovy
def call() {
// Execute build pipeline job
build_pipeline()
}
def build_pipeline() {
agent {
node {
label params.SLAVE
}
}
parameters {
string(name: 'SETTINGS_CONFIG_FILE_NAME', defaultValue: 'maven.settings')
string(name: 'SLAVE', defaultValue: 'new_slave')
}
environment {
mvn = "docker run -it --rm --name my-maven-project -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.3-jdk-8"
}
stages {
stage('Inject Settings.xml File') {
steps {
configFileProvider([configFile(fileId: "${env.SETTINGS_CONFIG_FILE_NAME}", targetLocation: "${env.WORKSPACE}")]) {
}
}
}
stage('Clean') {
steps {
sh "${mvn} clean"
}
}
stage('Lint') {
steps {
sh "${mvn} lint"
}
}
stage('Build package and execute tests') {
steps {
sh "${mvn} build"
}
}
}
post {
always {
archive "**/target/surefire-reports/*"
junit '**/target/surefire-reports/*.xml'
step([$class: 'JacocoPublisher'])
}
}
}
Jenkinsfile
@Library('pipeline-library-demo') _
jenkinsJob.call()
答案 0 :(得分:0)
所有有效的声明性管道必须包含在管道块中 例如:
pipeline {
/* insert Declarative Pipeline here */
/* import libraries and call functions */
}
答案 1 :(得分:0)
文件jenkinsJob.groovy只需要一个名称即可使用单一方法:
def call(Map params[:]){
// method body
}