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

JENKINS-25223: Allow executing scripts in JobProperty.prebuild phase #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arcivanov
Copy link

Creates the "prebuild" phase JobProperty section, allowing scripts to be executed after SCM is completed but before AbstractBuildExecution.doRun kicks in.
Also fixes NPE in EnvInjectJobProperty where disabling a section and saving before applying causes NPE on save

@jenkinsadmin
Copy link
Member

Thank you for a pull request! Please check this document for how the Jenkins project handles pull requests

@oleg-nenashev
Copy link
Member

IMHO, it's preferable to merge the functionality into https://github.com/jenkinsci/envinject-plugin/blob/master/src/main/java/org/jenkinsci/plugins/envinject/EnvInjectJobProperty.java (just to avoid user confusion and extra checkboxes)

@arcivanov
Copy link
Author

Well, the point was actually not to. If there is only one box it'll be either "before SCM" or "after SCM before doRun". There is no reason to not allow both but I agree it makes sense to work on the naming for the boxes.

Scenario could be:

  1. Prep environment, install SCM
  2. Run SCM
  3. Use SCM'ed data to setup the rest of the environment before doRun kicks in.

@daniel-beck
Copy link
Member

Isn't it time the UI was changed to something more like Git Plugin's Additional Behaviors, or how Email-ext changed the per-trigger recipients? It's getting ridiculous with the boxes.

@arcivanov
Copy link
Author

I'm not opposed to the change in the UI. Let me see how additional behaviors work in Git and how long it'll take to get it done.

@arcivanov
Copy link
Author

Just out of curiousity, what section of the job would you like the configuration to reside? I would vote for top-most Job Property section for all, i.e. for "before SCM", "after SCM, before doRun", "shortly after doRun" (not real labels).

@oleg-nenashev
Copy link
Member

I'd like to get this feature merged. BTW, a combination of EnvInject build step and https://wiki.jenkins-ci.org/display/JENKINS/pre-scm-buildstep seems to provide this feature.


@SuppressWarnings("unused")
public EnvInjectJobPropertyInfo getInfo()
{
Copy link
Member

Choose a reason for hiding this comment

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

It would be great if you follow the plugin's codestyle. Brackets are being placed at the same line as the declaration in the plugin

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, I'll work on the style, standby.

@arcivanov
Copy link
Author

@oleg-nenashev

BTW, a combination of EnvInject build step and https://wiki.jenkins-ci.org/display/JENKINS/pre-scm-buildstep

Actually I don't think it does, as specific stated purpose is (emphasis added):

Creates the "prebuild" phase JobProperty section, allowing scripts to be executed after SCM is completed but before AbstractBuildExecution.doRun kicks in.

This allows to get a code tree sucked in and then configure things like JDK, Maven or any other build environment component based on information retrieved from the SCM.

@oleg-nenashev
Copy link
Member

It would be great to have a 1 or 2 unit tests for the feature (just to be sure it works correctly when we apply new changes). It should not be a big deal, because it's possible to copy some bits from #58. Could you add such tests?

@arcivanov
Copy link
Author

I'll add the tests

@arcivanov
Copy link
Author

@oleg-nenashev Tests added, latest functionality synced up. Happy? 😄

@oleg-nenashev
Copy link
Member

@arcivanov
Thanks a lot for your efforts. The PR looks good to me. Somebody may be concerned by another checkbox in the job property, but IMO it's OK in the current case (and can be a refactoring subject for envinject-2.0).

Adding the PR to the next major release milestone. It would be great if you squash commits

@oleg-nenashev oleg-nenashev added this to the 1.93 milestone Aug 24, 2015
…d phase

Creates the "prebuild" phase JobProperty section, allowing scripts to be executed after SCM is completed but before AbstractBuildExecution.doRun kicks in.
Also fixes NPE in EnvInjectJobProperty where disabling a section and saving before applying causes NPE on save
@arcivanov
Copy link
Author

@oleg-nenashev squashed, commit message updated to reflect fixed status

@arcivanov
Copy link
Author

@oleg-nenashev bump

@oleg-nenashev
Copy link
Member

@daniel-beck

Isn't it time the UI was changed to something more like Git Plugin's Additional Behaviors, or how Email-ext changed the per-trigger recipients? It's getting ridiculous with the boxes.

It definitely makes sense (as well as the rework of the internal layout). BTW it should be done as a general envinject-2.0 effort.

I'm pretty OK to merge the PR now, but I would plan to rework it during the 2.0 rework and probably make the incompatible change.

@arcivanov
Copy link
Author

I agree that UI rework is out of scope for this PR - it was my intention to only introduce additional functionality.


if (onObject != null) {
EnvInjectPrebuildJobProperty envInjectJobProperty = new EnvInjectPrebuildJobProperty();
EnvInjectJobPropertyInfo info = req.bindParameters(EnvInjectJobPropertyInfo.class, "envInjectInfoPrebuildJobProperty.");

Choose a reason for hiding this comment

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

MINOR Method 'StaplerRequest.bindParameters(...)' is deprecated. rule
MAJOR Rename "info" which hides the field declared at line 50. rule
MINOR Split this 136 characters long line (which is greater than 120 authorized). rule

}

private void setContributors(StaplerRequest req, EnvInjectPrebuildJobProperty envInjectJobProperty, JSONObject onJSONObject) {
if (!onJSONObject.containsKey("contributors")) {

Choose a reason for hiding this comment

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

MINOR Define a constant instead of duplicating this literal "contributors" 3 times. rule

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants