我正在尝试编写一个jenkins文件,它允许我有一个非阻塞输入步骤(即一个输入步骤将使用一个flyweight执行器而不是一个重量级执行器)。虽然我已经设法在一个测试项目中做到了这一点,但是我在我的文件中为我的真实项目添加了一个环境部分。我的jenkins文件目前看起来像这样......
pipeline {
agent none
stages {
stage('Env Set Up'){
agent {label 'cm-linux-15916'}
environment {
def JAVA_HOME = tool('1.8.0.65_Linux')
def MAVEN_EXEC = tool('3.3.3_Linux')
PATH="${JAVA_HOME}/jre/bin:${MAVEN_EXEC}/bin:/build/build_tools/nodejs/6.7.0/bin/:$PATH"
}
}
stage('DEV Build & Sonar') {
agent {label 'cm-linux-15916'}
steps {
echo 'DEV BUILD STARTED HERE...'
sh("/build_tools/maven/apache-maven-3.3.3/bin/mvn versions:set -DnewVersion=${Major}.${Minor}.${Point}.${BUILD_NUMBER}-SNAPSHOT -X")
sh("/build_tools/maven/apache-maven-3.3.3/bin/mvn clean org.jacoco:jacoco-maven-plugin:0.7.4.201502262128:prepare-agent deploy sonar:sonar")
}
}
stage('DEV Deploy') {
agent {label 'cm-linux-15916'}
steps {
withCredentials([usernamePassword(credentialsId: '2b714cb5-d136-4555-97bc-f33ba1695a02',
usernameVariable: 'uname',
passwordVariable: 'passwd')])
{
sh('chmod 755 ansible_dev.sh')
sh('./ansible_dev.sh')
sh('chmod 644 ansible_dev.sh')
}
}
}
stage('SIT Build & Deploy?') {
agent none
steps {
timeout(time:24, unit:'HOURS') {
input('Do you want to proceed with SIT deployments?')
}
}
}
这给了我
WorkflowScript: 4: Nothing to execute within stage "Env Set Up" @ line 4, column 5.
stage('Env Set Up'){
我也尝试过以下方法......
pipeline {
agent none
environment {
def JAVA_HOME = tool('1.8.0.65_Linux')
def MAVEN_EXEC = tool('3.3.3_Linux')
PATH="${JAVA_HOME}/jre/bin:${MAVEN_EXEC}/bin:/build/build_tools/nodejs/6.7.0/bin/:$PATH"
}
stages {
stage('DEV Build & Sonar') {
agent {label 'cm-linux-15916'}
steps {
echo 'DEV BUILD STARTED HERE...'
sh("/build_tools/maven/apache-maven-3.3.3/bin/mvn versions:set -DnewVersion=${Major}.${Minor}.${Point}.${BUILD_NUMBER}-SNAPSHOT -X")
sh("/build_tools/maven/apache-maven-3.3.3/bin/mvn clean org.jacoco:jacoco-maven-plugin:0.7.4.201502262128:prepare-agent deploy sonar:sonar")
}
}
stage('DEV Deploy') {
agent {label 'cm-linux-15916'}
steps {
withCredentials([usernamePassword(credentialsId: '2b714cb5-d136-4555-97bc-f33ba1695a02',
usernameVariable: 'uname',
passwordVariable: 'passwd')])
{
sh('chmod 755 ansible_dev.sh')
sh('./ansible_dev.sh')
sh('chmod 644 ansible_dev.sh')
}
}
}
stage('SIT Build & Deploy?') {
agent none
steps {
timeout(time:24, unit:'HOURS') {
input('Do you want to proceed with SIT deployments?')
}
}
}
这给了我
Required context class hudson.model.Node is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
我真的很难在这方面得到正确的语法,没有环境部分我可以按预期工作。任何人都可以帮助我吗?
更新
我最近的尝试是将env变量包含在第一阶段的脚本部分中,如下所示
pipeline {
agent none
stages {
stage('DEV Build & Sonar') {
agent {label 'cm-linux-15916'}
steps {
script{
def JAVA_HOME = tool('1.8.0.65_Linux')
def MAVEN_EXEC = tool('3.3.3_Linux')
//PATH="${JAVA_HOME}/jre/bin:${MAVEN_EXEC}/bin:/build/build_tools/nodejs/6.7.0/bin/:$PATH"
PATH="/build/build_tools/jdk/1.8.0.65/jre/bin:/build/build_tools/nodejs/6.7.0/bin/:$PATH"
JAVA_HOME="/build/build_tools/jdk/1.8.0.65/jre/"
echo 'DEV BUILD STARTED HERE...'
sh("/build_tools/maven/apache-maven-3.3.3/bin/mvn versions:set -DnewVersion=${Major}.${Minor}.${Point}.${BUILD_NUMBER}-SNAPSHOT -X")
sh("/build_tools/maven/apache-maven-3.3.3/bin/mvn clean org.jacoco:jacoco-maven-plugin:0.7.4.201502262128:prepare-agent deploy sonar:sonar")
}
}
}
stage('DEV Deploy') {
agent {label 'cm-linux-15916'}
steps {
withCredentials([usernamePassword(credentialsId: '2b714cb5-d136-4555-97bc-f33ba1695a02',
usernameVariable: 'uname',
passwordVariable: 'passwd')])
{
sh('chmod 755 ansible_dev.sh')
sh('./ansible_dev.sh')
sh('chmod 644 ansible_dev.sh')
}
}
}
stage('SIT Build & Deploy?') {
agent none
steps {
timeout(time:24, unit:'HOURS') {
input('Do you want to proceed with SIT deployments?')
}
}
}
虽然我现在收到错误,但感觉更接近我想要的......
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project orc-admin-service-wlp: Fatal error compiling: invalid target release: 1.8 -> [Help 1]
这似乎来自mvn clean step