Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing method #285

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ abstract class DeclarativePipelineTest extends BasePipelineTest {

def pipelineInterceptor = { Closure closure ->
GenericPipelineDeclaration.binding = delegate.binding
GenericPipelineDeclaration.pipelineOwner = closure.owner
GenericPipelineDeclaration.createComponent(DeclarativePipeline, closure).execute(delegate)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ abstract class GenericPipelineDeclaration {
PostDeclaration post
Map<String, StageDeclaration> stages = [:]
static def binding = null
static def pipelineOwner = null

static <T> T createComponent(Class<T> componentType,
@DelegatesTo(strategy = DELEGATE_ONLY) Closure<T> closure) {
Expand All @@ -33,6 +34,22 @@ abstract class GenericPipelineDeclaration {
return retVal
}
}
componentInstance.metaClass.methodMissing = { String methodName, args ->
def retVal
def metaMethod = componentInstance.metaClass.getMetaMethod(methodName, args)
if (metaMethod) {
retVal = componentInstance.invokeMethod(methodName, args)
} else {
metaMethod = pipelineOwner.metaClass.getMetaMethod(methodName, args)
if(metaMethod){
retVal = pipelineOwner.invokeMethod(methodName, args)
} else {
throw new MissingMethodException(methodName, componentInstance.class, args)
}
}
return retVal
}

rehydrate.call()
return componentInstance
}
Expand Down
11 changes: 9 additions & 2 deletions src/test/jenkins/jenkinsfiles/Agent_bindings_Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

def AGENT = 'someLabel'

pipeline {
agent none
stages {
Expand All @@ -18,6 +16,12 @@ pipeline {
sh 'java -version'
}
}
stage('Example Release') {
agent agentName()
steps {
echo "Deploy to ${AGENT}"
}
}
stage('Example Deploy') {
agent AGENT
steps {
Expand All @@ -26,3 +30,6 @@ pipeline {
}
}
}
private String agentName(){
return 'someLabel';
}