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

Resolved a regression of template_methods working when overloaded by library steps #293

Merged
merged 1 commit into from
Jun 24, 2022
Merged
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 @@ -90,11 +90,7 @@ abstract class TemplatePrimitiveInjector implements ExtensionPoint{
WorkflowRun run = flowOwner.run()
TemplatePrimitiveCollector collector = new TemplatePrimitiveCollector()
run.addOrReplaceAction(collector) // may be used by one of the injectors
invoke("injectPrimitives", exec, config).each{ namespace ->
if(namespace){
collector.addNamespace(namespace)
}
}
invoke(run, collector, "injectPrimitives", exec, config)
invoke("validatePrimitives", exec, config, collector)
run.addOrReplaceAction(collector)
}
Expand Down Expand Up @@ -142,8 +138,7 @@ abstract class TemplatePrimitiveInjector implements ExtensionPoint{
* @param phase the phase to invoke
* @param args the args to pass to the phase
*/
private static List<TemplatePrimitiveNamespace> invoke(String phase, Object... args){
List<TemplatePrimitiveNamespace> namespaces = []
private static void invoke(WorkflowRun run = null, TemplatePrimitiveCollector collector = null, String phase, Object... args){
List<Class<? extends TemplatePrimitiveInjector>> failedInjectors = []
Graph<Class<? extends TemplatePrimitiveInjector>, DefaultEdge> graph = createGraph(phase, args)
AggregateException errors = new AggregateException()
Expand All @@ -152,7 +147,11 @@ abstract class TemplatePrimitiveInjector implements ExtensionPoint{
try{
// check if a dependent injector has failed, if so, don't execute
if(!(getPrerequisites(injector, phase, args).intersect(failedInjectors))){
namespaces << injector.invokeMethod(phase, args)
TemplatePrimitiveNamespace namespace = injector.invokeMethod(phase, args)
if(namespace){
collector.addNamespace(namespace)
run.addOrReplaceAction(collector)
}
}
} catch(any){
CpsFlowExecution exec = args[0]
Expand All @@ -167,7 +166,6 @@ abstract class TemplatePrimitiveInjector implements ExtensionPoint{
if(errors.size()) { // this phase failed throw an exception
throw errors
}
return namespaces
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,4 +866,39 @@ class StepWrapperSpec extends Specification {
jenkins.assertBuildStatusSuccess(run)
}

def "Template Methods work when no library step is present"(){
given:
WorkflowJob job = TestUtil.createAdHoc(jenkins,
config: 'template_methods{ build }',
template: 'build()'
)

when:
WorkflowRun run = job.scheduleBuild2(0).get()

then:
jenkins.assertBuildStatusSuccess(run)
jenkins.assertLogContains("Step build is not implemented.", run)
}

@Issue("https://github.com/jenkinsci/templating-engine-plugin/issues/291")
def "Pipeline Passes when library step overloads template method step"(){
given:
libProvider.addStep("gradle", "build", "void call(){ println 'gradle build' }")
WorkflowJob job = TestUtil.createAdHoc(jenkins,
config: """
libraries{ gradle }
template_methods{ build }
""",
template: 'build()'
)

when:
WorkflowRun run = job.scheduleBuild2(0).get()

then:
jenkins.assertBuildStatusSuccess(run)
jenkins.assertLogContains("gradle build", run)
}

}