forked from v1v/jenkinslint-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-46162] Support workflow/pipeline linting (#30)
* Supporting pipeline jobs, fixed some bugs, bumped minimal version to allow the usage of the pipelines * Supporting GroovySandbox checker only in Jenkinsfiles, aka WorkflowJobs * [JENKINS-46162] Support Pipeline project to be linted * Added TestCases for the Pipeline jobs * Enable System Groovy detection * Missing testcases * Enabling JenkinsLint action for pipelines/workflows Change-Id: Ideaa90900b836d2a2f115fc7eefa7c2ab5533197 * Support pipeline timer trigger check Change-Id: I857d85210a0f95c22226798320508132cecaf9fa * Fixed TimeoutChecker for pipeline (some false positives) Change-Id: I2f9cdd04a73702ffa16cb7050123dc6a63fb759b * Support pipeline PollingSCMtrigger check Change-Id: I7ef1a3228096c2e43713495629e044bbb141d898
- Loading branch information
Showing
40 changed files
with
399 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
src/main/java/org/jenkins/ci/plugins/jenkinslint/LintActionFactory.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
src/main/java/org/jenkins/ci/plugins/jenkinslint/SlaveLintActionFactory.java
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
src/main/java/org/jenkins/ci/plugins/jenkinslint/check/GroovySandboxChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.jenkins.ci.plugins.jenkinslint.check; | ||
|
||
import hudson.model.Item; | ||
import hudson.model.Job; | ||
import org.jenkins.ci.plugins.jenkinslint.model.AbstractCheck; | ||
|
||
import java.util.logging.Level; | ||
|
||
/** | ||
* @author Victor Martinez | ||
*/ | ||
public class GroovySandboxChecker extends AbstractCheck { | ||
|
||
public GroovySandboxChecker(boolean enabled) { | ||
super(enabled); | ||
this.setDescription(Messages.GroovySandboxCheckerDesc()); | ||
this.setSeverity(Messages.GroovySandboxCheckerSeverity()); | ||
} | ||
|
||
public boolean executeCheck(Item item) { | ||
LOG.log(Level.FINE, "executeCheck " + item); | ||
if (item instanceof Job) { | ||
// Pipeline support | ||
if (item.getClass().getSimpleName().equals("WorkflowJob")) { | ||
try { | ||
Object getDefinition = item.getClass().getMethod("getDefinition", null).invoke(item); | ||
if (getDefinition.getClass().getSimpleName().equals("CpsFlowDefinition")) { | ||
return !isSandbox(getDefinition); | ||
} | ||
} catch (Exception e) { | ||
LOG.log(Level.FINE, "Exception " + e.getMessage(), e.getCause()); | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private boolean isSandbox(Object object) { | ||
boolean status = true; | ||
if (object != null) { | ||
try { | ||
Object isSandbox = object.getClass().getMethod("isSandbox", null).invoke(object); | ||
return ((Boolean) isSandbox); | ||
} catch (Exception e) { | ||
LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause()); | ||
} | ||
} | ||
return status; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.