我想將jenkinsfile中的內容分隔成一個groovy腳本。但它不能調用這些腳本: 以下是代碼:如何從Jenkins文件調用groovy腳本?
#!/usr/bin/env groovy
node('test-node'){
stage('Checkout') {
echo "${BRANCH_NAME} ${env.BRANCH_NAME}"
scm Checkout
}
stage('Build-all-targets-in-parallel'){
def workspace = pwd()
echo workspace
parallel(
'first-parallel-target' :
{
// Load the file 'file1.groovy' from the current directory, into a variable called "externalMethod".
//callScriptOne()
def externalMethod = load("file1.groovy")
// Call the method we defined in file1.
externalMethod.firstTest()
},
'second-parallel-target' :
{
//callScriptTwo()
def externalMethod = load("file2.groovy")
// Call the method we defined in file1.
externalMethod.testTwo()
}
)
}
stage('Cleanup workspace'){
deleteDir()
}
}
file.groovy
#!groovy
def firstTest(){
node('test-node'){
stage('build'){
echo "Second stage"
}
stage('Cleanup workspace'){
deleteDir()
}
}
}
貌似Jenkinsfile能夠調用file1.groovy但總是給我一個錯誤:
java.lang.NullPointerException: Cannot invoke method firstTest() on null object
我不認爲'負載(「file1.groovy」 )'找到你的groovy文件試圖調試。 – dynamo