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
Conversation
0e87833
to
b6d7109
Compare
Can't we keep the existing interface around and do something with Java 8 default methods? |
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 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 |
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. |
Sounds reasonable, will try to do. |
b6d7109
to
b178836
Compare
+ Adds new method with default implementation in EnvironmentContributingAction to support Runs + Marks AbstractBuild as deprecated + Adds default implementation for deprecated method for backward compatiblity.
b178836
to
33cc3cf
Compare
@daniel-beck, @oleg-nenashev, @rsandell, done. Please, take a look. |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. | ||
*/ |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
👍 |
@jenkinsci/code-reviewers |
No negative feedback after 1 week, merging |
* @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, |
There was a problem hiding this comment.
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?
Should not have been merged without downstream PRs demonstrating the API in action. In fact I think the signature is wrong; the |
@jglick There's still time to revert. |
No, this should not be here. It will not work anyway.
|
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 |
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. |
Confirmed how? “Confirmation” to me means a downstream PR using a timestamped snapshot dep on the core PR showing an
There is no context here. Only a
Sure, but unfortunately I just cannot keep up with all those messages, nor
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()); |
There was a problem hiding this comment.
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
.
BTW jenkinsci/gerrit-trigger-plugin#319 may be related, but it is not downstream—does not demonstrate that this works. |
I propose to revert before 2.76 gets cut on Sunday or Monday and the API is set in stone. |
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 |
Or perhaps, worse, always |
@@ -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) { |
There was a problem hiding this comment.
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.
Just checked. It is |
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
See JENKINS-29537.
WorkflowJob
s as well asAbstractProject
s.Downstream PR:
@jglick, @rsandell