-
Notifications
You must be signed in to change notification settings - Fork 415
Expand file tree
/
Copy pathFindStringInPipeline.groovy
More file actions
28 lines (25 loc) · 1.01 KB
/
FindStringInPipeline.groovy
File metadata and controls
28 lines (25 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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())
}
}
}