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

Update 3-pipeline-lifecycle-hooks.adoc #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -75,8 +75,7 @@ Splunk: beginning of the pipeline!

=== Add Before and After Step Execution Hooks

Let's add some hooks that inject themselves both before and after each step is executed in the pipeline.

Let's add some hooks that inject themselves both before and after each step is executed in the pipeline:

.libraries/splunk/steps/splunk_step_watcher.groovy
[source,groovy]
Expand Down Expand Up @@ -246,7 +245,7 @@ Finished: SUCCESS

Let's try out one more hook to get executed when the pipeline has finished:

.libraries/splunk/splunk_pipeline_end.groovy
.libraries/splunk/steps/splunk_pipeline_end.groovy
[source,groovy]
----
@CleanUp
Expand Down Expand Up @@ -416,11 +415,14 @@ We call this functionality *Conditional Hook Execution*.

Let's see it in action.

Update the `@AfterStep` created in *libraries/splunk/splunk_step_watcher.groovy* to:
Update the `@AfterStep` created in *libraries/splunk/steps/splunk_step_watcher.groovy* to:

[source,groovy]
----
@AfterStep({ hookContext.step.equals("static_code_analysis") })
void after(){
println "Splunk: running after the ${hookContext.library} library's ${hookContext.step} step"
}
----

Rerun the pipeline and notice that now, the hook has been restricted to only run after the desired step.
Expand All @@ -439,6 +441,9 @@ To do this, update the `@AfterStep` annotation again to be:
[source,groovy]
----
@AfterStep({ hookContext.step in config.afterSteps })
void after(){
println "Splunk: running after the ${hookContext.library} library's ${hookContext.step} step"
}
----

Now, we can conditionally execute the hook by checking if the name of the step that was just executed is in an array called `afterSteps` defined as part of the `splunk` library in the Pipeline Configuration!
Expand Down