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-29537] EnvironmentContributingAction compatible with Workflow #2975

Merged
merged 2 commits into from Aug 22, 2017

Conversation

Jimilian
Copy link
Contributor

@Jimilian Jimilian commented Aug 10, 2017

  • Adds GenericEnvironmentContributingAction
  • Deprecates EnvironmentContributingAction

See JENKINS-29537.

  • Internal: JENKINS-29537, Add GenericEnvironmentContributingAction that supports WorkflowJobs as well as AbstractProjects.

Downstream PR:

@jglick, @rsandell

@daniel-beck
Copy link
Member

Can't we keep the existing interface around and do something with Java 8 default methods?

@oleg-nenashev
Copy link
Member

oleg-nenashev commented Aug 10, 2017

Yes, new interface is not required for Java 8. You can even make the default method to call the obsolete Abstract Project one if implemented (see Util.isOverridden()). And then you can make the old implementation optional as well by offering the default method.

I was considering doing similar patch for https://issues.jenkins-ci.org/browse/JENKINS-42614 (Pipeline Support in EnvInject). According to that experience I would definitely recommend adding a an optional @CheckForNull Node node parameter to the method. Otherwise it would complicated to integrate plugins depending on the Node state

@rsandell
Copy link
Member

rsandell commented Aug 10, 2017

Yes, if this becomes just an addition to the old interface I believe we can use it in plugins without needing to bump dependency to a newer core.

@Jimilian
Copy link
Contributor Author

Sounds reasonable, will try to do.

@oleg-nenashev oleg-nenashev added the work-in-progress The PR is under active development, not ready to the final review label Aug 11, 2017
+ Adds new method with default implementation in EnvironmentContributingAction to support Runs
+ Marks AbstractBuild as deprecated
+ Adds default implementation for deprecated method for backward
compatiblity.
@Jimilian
Copy link
Contributor Author

@daniel-beck, @oleg-nenashev, @rsandell, done. Please, take a look.

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.

LGTM 👍 , just minor Javadoc comments. Also created https://issues.jenkins-ci.org/browse/JENKINS-46169 as a follow-up

@@ -2302,6 +2302,9 @@ public EnvVars getEnvironment() throws IOException, InterruptedException {
for (EnvironmentContributor ec : EnvironmentContributor.all().reverseView())
ec.buildEnvironmentFor(this,env,listener);

for (EnvironmentContributingAction a : getActions(EnvironmentContributingAction.class))
a.buildEnvVars(this,env,n);
Copy link
Member

Choose a reason for hiding this comment

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

Nice 2 have for new extension invocations: try/catch unexpected runtime exceptions. NIT in this case since there is same old code above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my personal perspective some more generic way to do it is needed. I.e. some decorator that wraps all calls by try/catch. Or at least forces developers to do it.

Copy link
Member

Choose a reason for hiding this comment

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

I agree. I was thinking about adding a wrapper for it using the Java 8 magic.
The only concern is about performance requirements for particular extensions.

* The node execute on. Can be null.
* @param env
* Environment variables should be added to this map.
*/
Copy link
Member

Choose a reason for hiding this comment

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

@since TODO

* @param run
* The calling build. Never null.
* @param node
* The node execute on. Can be null.
Copy link
Member

Choose a reason for hiding this comment

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

Can be {@code null} when the Run is not binded to the node (e.g. in Pipeline outside the {@code node() step})

* Called by {@link Run} or {@link AbstractBuild} to allow plugins to contribute environment variables.
*
* @param run
* The calling build. Never null.
Copy link
Member

Choose a reason for hiding this comment

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

Instead of "Never null" it's better to add the @Nonnull annotation to the method argument

@oleg-nenashev oleg-nenashev added needs-more-reviews Complex change, which would benefit from more eyes on-hold This pull request depends on another event/release, and it cannot be merged right now and removed work-in-progress The PR is under active development, not ready to the final review labels Aug 14, 2017
@rsandell
Copy link
Member

👍

@oleg-nenashev
Copy link
Member

@jenkinsci/code-reviewers

@oleg-nenashev oleg-nenashev added ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback and removed needs-more-reviews Complex change, which would benefit from more eyes on-hold This pull request depends on another event/release, and it cannot be merged right now labels Aug 22, 2017
@oleg-nenashev
Copy link
Member

No negative feedback after 1 week, merging

@oleg-nenashev oleg-nenashev merged commit c60735a into jenkinsci:master Aug 22, 2017
@Jimilian Jimilian deleted the JENKINS-29537 branch August 22, 2017 08:35
* @param run
* The calling build. Never null.
* @param node
* The node execute on. Can be {@code null} when the Run is not binded to the node,
Copy link
Member

Choose a reason for hiding this comment

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

Seems inappropriate. What is this argument for?

@jglick
Copy link
Member

jglick commented Aug 24, 2017

Should not have been merged without downstream PRs demonstrating the API in action. In fact I think the signature is wrong; the Node will always be null when used from Pipeline—the supposed purpose of the change.

@daniel-beck
Copy link
Member

@jglick There's still time to revert.

@jglick
Copy link
Member

jglick commented Aug 24, 2017

According to that experience I would definitely recommend adding a an optional @CheckForNull Node node parameter to the method. Otherwise it would complicated to integrate plugins depending on the Node state

No, this should not be here. It will not work anyway.

  • for an AbstractBuild, you can already call getBuildOn
  • for a WorkflowRun, there is no specific Node without a StepContext, which is not going to be here

@oleg-nenashev
Copy link
Member

I propose to discuss it first before reverting. I confirm this API is useful, and the nullable Node is also useful. I had pretty same PoC for EnvInject. Even Pipeline can contribute node when it is available in the context.

@jenkinsci/code-reviewers were pinged and definitely had enough time to provide feedback

@daniel-beck
Copy link
Member

It's much easier to properly re-do an addition that was backed out, than to fix something with conceptual problems once it's in.

@jglick
Copy link
Member

jglick commented Aug 24, 2017

I confirm this API is useful, and the nullable Node is also useful.

Confirmed how? “Confirmation” to me means a downstream PR using a timestamped snapshot dep on the core PR showing an EnvironmentContributingAction implementation implementing the new method, and using the Node parameter, with a functional test using createSlave or similar to demonstrate that the correct node is in fact selected.

Even Pipeline can contribute node when it is available in the context.

There is no context here. Only a Run, which can have any number of active contexts.

@jenkinsci/code-reviewers were pinged and definitely had enough time to provide feedback

Sure, but unfortunately I just cannot keep up with all those messages, nor @-mentions. For the future, best to “request a review” from me, which at least shows up in my personal board.

It's much easier to properly re-do an addition that was backed out, than to fix something with conceptual problems once it's in.

Yes, an API is forever I am afraid.

@@ -881,7 +881,7 @@ public EnvVars getEnvironment(TaskListener log) throws IOException, InterruptedE
e.buildEnvVars(env);

for (EnvironmentContributingAction a : getActions(EnvironmentContributingAction.class))
a.buildEnvVars(this,env);
a.buildEnvVars(this,env,getBuiltOn());
Copy link
Member

Choose a reason for hiding this comment

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

AFAICT this loop should just be deleted since it is already being called in the super; otherwise we would be calling each EnvironmentContributingAction twice on a single AbstractBuild.

@jglick
Copy link
Member

jglick commented Aug 24, 2017

BTW jenkinsci/gerrit-trigger-plugin#319 may be related, but it is not downstream—does not demonstrate that this works.

@jglick
Copy link
Member

jglick commented Aug 24, 2017

I propose to revert before 2.76 gets cut on Sunday or Monday and the API is set in stone.

@oleg-nenashev
Copy link
Member

I propose to give @Jimilian an opportunity to respond first. I will process the feedback above. If we have no agreement, let's revert it on Friday's evening in EU

@jglick
Copy link
Member

jglick commented Aug 24, 2017

the Node will always be null when used from Pipeline

Or perhaps, worse, always Jenkins, i.e. master, even when the build is in fact running some node block on an agent. Not sure which it is offhand.

@@ -138,10 +138,11 @@ public void createBuildWrappers(AbstractBuild<?,?> build, Collection<? super Bui
}
}

public void buildEnvVars(AbstractBuild<?,?> build, EnvVars env) {
@Override
public void buildEnvVars(Run<?,?> run, EnvVars env, Node node) {
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 going to cause this code to process Pipeline build parameters twice, until workflow-job is updated to disable its own copy of the logic when running on a sufficiently new core version. Probably harmless but needs to be investigated.

@jglick
Copy link
Member

jglick commented Aug 24, 2017

Not sure which it is offhand.

Just checked. It is null in all cases. So the node parameter is clearly useless and misleading: for WorkflowRun will always be null; for AbstractBuild will be the same as getBuiltOn.

@jglick
Copy link
Member

jglick commented Aug 24, 2017

Rather than reverting per se, I filed #2993 to correct the problems I identified in this PR, and jenkinsci/workflow-job-plugin#67 to demonstrate its usefulness in a plugin (though a PR showing a plugin implementation of the new method would be valuable too).

* @param build
* The calling build. Never null.
* @param env
* Environment variables should be added to this map.
*/
void buildEnvVars(AbstractBuild<?, ?> build, EnvVars env);
@Deprecated
@Restricted(ProtectedExternally.class)
Copy link
Member

Choose a reason for hiding this comment

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

Causing me problems in jenkinsci/maven-plugin#109. Why was this necessary?

Copy link
Member

Choose a reason for hiding this comment

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

It was supposed to make upgrading plugin maintainers to migrate to new APIs. But I agree that such approach creates issues in Jenkinsfiles testing against newer cores. PCT is not my concern, it should probably ignore @Restricted annotations and just report them in the output without failing the entrire build

jglick added a commit to jglick/maven-plugin that referenced this pull request Jan 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
5 participants