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

Create FindStringInPipeline.groovy #121

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
28 changes: 28 additions & 0 deletions FindStringInPipeline.groovy
Original file line number Diff line number Diff line change
@@ -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())
}
}
}