From 6976d2370feb3a051b5ed249c6e09420d4c8b0c7 Mon Sep 17 00:00:00 2001 From: Alex Taylor Date: Wed, 11 Mar 2020 15:32:42 -0400 Subject: [PATCH] Create FindStringInPipeline.groovy Created a script to go and find a specific string in all your pipelines when possible --- FindStringInPipeline.groovy | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 FindStringInPipeline.groovy diff --git a/FindStringInPipeline.groovy b/FindStringInPipeline.groovy new file mode 100644 index 0000000..b59ed77 --- /dev/null +++ b/FindStringInPipeline.groovy @@ -0,0 +1,28 @@ +/* +Author: Alex Taylor +Since: March 2020 +Description: This searches over all pipeline scripts locally and on the last build if run via Jenkinsfile for a string +This is helpful for when you need to do a mass fix on a bunch of pipelines +Parameters: searchString +Scope: Jenkins +*/ + +import org.jenkinsci.plugins.workflow.job.* +import org.jenkinsci.plugins.workflow.cps.* + +def searchString = "Looking for this String" + +Jenkins.getInstance().getAllItems(WorkflowJob.class).each(){pipeline -> + if(pipeline.getDefinition() instanceof CpsFlowDefinition + && pipeline.getDefinition() != null + && pipeline.getDefinition().script.contains(searchString)){ + println("Need to fix: " + pipeline.getDisplayName()) + } else { + if(pipeline.getDefinition() instanceof CpsFlowDefinition + && pipeline.getLastBuild() != null + && pipeline.getLastBuild().getExecution() != null + && pipeline.getLastBuild().getExecution().script.contains(searchString)){ + println("Need to fix Jenkinsfile: " + pipeline.getDisplayName()) + } + } +} \ No newline at end of file