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

Added a 'lint' command #511

Merged
merged 5 commits into from
Jun 2, 2021
Merged

Conversation

pawoolley
Copy link
Contributor

Added a lint command, which is akin to when a Jenkinsfile is POSTed to $JENKINS_URL/pipeline-model-converter/validate.

This has the benefits of being:

  1. quicker to lint files because, after the validation stage, if the file passes, the pipeline isn't then executed.
  2. safer to lint files because, after the validation stage, the pipeline isn't executed, which might have unwanted effects or change the state of other systems.

Running...
jfr-run

...vs. linting...
jfr-lint

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your master branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@pawoolley pawoolley requested a review from a team as a code owner May 28, 2021 11:13
README.adoc Show resolved Hide resolved
.setAuthor(johnDoe)
.setCommitter(johnDoe)
.setMessage("Test commit")
.setSign(false) // Required if you're locally setup for signed commits.
Copy link
Contributor Author

@pawoolley pawoolley May 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locally, my gitconfig is setup for signed commits and that was causing this test to fail with a signing service is not available exception message. Using org.jenkinsci.plugins.gitclient.GitClient, it was not possible to configure it to disable signed requests. Switching to org.eclipse.jgit.api.Git allows this an lets the test pass for folk with setups like mine.

Co-authored-by: Jesse Glick <jglick@cloudbees.com>
@pawoolley pawoolley requested review from jglick and removed request for a team May 28, 2021 13:28
@pawoolley
Copy link
Contributor Author

and removed request for jenkinsci/jenkinsfile-runner-developers now

Err...no I didn't 🤔

@oleg-nenashev oleg-nenashev added the enhancement New feature or request label May 29, 2021
Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a few minor comments. Thanks @pawoolley !

JenkinsLauncher<?> launcher;
if (command instanceof RunJenkinsfileCommand) {
launcher = new JenkinsfileRunnerLauncher((RunJenkinsfileCommand) command);
} else if (command instanceof LintJenkinsfileCommand) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later some simplification will be needed for the Command => Launcher mapping. Fine for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I did take a quick look at this. Thought it would be good if each JenkinsLauncherCommand had a factory method that allowed it to create the right type of JenkinsLauncher, but that would have introduced a circular dependency between the bootstrap and setup modules. Will leave it for now while it's still simple.

@Override
protected int doLaunch() throws Exception {
// So that the payload code has all the access to the system
ACL.impersonate(ACL.SYSTEM);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the deprecated call, right? Better to do try-with-resources method so that we do not leak the context

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't do a try-with-resources with Java 8, so swapped to a try-finally block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait! What? Yes, you can do a try-with-resource at Java 8 🤦
My IDE is lying. One second, let me check that again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Changed it to a try-with-resources. Also took the liberty of changing JenkinsfileRunnerLauncher too, so that both files are consistent.

try {
// Attempt to call the scriptToPipelineDef method of the Converter class. This is the same as what
// happens when a Jenkinsfile is POSTed to $JENKINS_URL/pipeline-model-converter/validate.
System.out.println("Linting...");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for now though I want to replace everything by loggers later

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI fails because of the infra issue. The code looks good overall, thanks @pawoolley !

@oleg-nenashev oleg-nenashev merged commit 4a447e9 into jenkinsci:master Jun 2, 2021
@pawoolley pawoolley deleted the add-lint-cmd branch June 2, 2021 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants