-
Notifications
You must be signed in to change notification settings - Fork 108
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
properly get displayname of node #38
Conversation
use the executor of the build to get the node. builtOn is set too late for us to get the node and we end up using master
@@ -138,7 +139,7 @@ public TestData(Action action) { | |||
public BuildData(AbstractBuild<?, ?> build, Date currentTime, TaskListener listener) { | |||
initData(build, currentTime); | |||
|
|||
Node node = build.getBuiltOn(); | |||
Node node = build.getExecutor().getOwner().getNode(); |
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.
how about we try to use getBuiltOn()
first and fall back to getExecutor().getOwner().getNode()
if the first one is null
? Just to be on the safe side
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 must be null if you follow the logic.
In the method execute of class Run you will see that the BuildWrappers are initialized from method createBuildListener. But the builtOn is only set when later in the execute the RunExecution.run is called (which actually is AbstractBuild.AbstractBuildExecution.run)
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 get that. However this is relying on implementation details. With the current low test coverage I'd prefer to be as conservative as possible.
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.
Another way to look at it is this.
It seems pointless for anyone to call getBuiltOn()
if getExecutor().getOwner().getNode()
can give you the same result and do it earlier.
I see there is an @Exported getBuiltOnStr()
method so remote API is the only sane use case.
Is getBuiltOn()
purely a legacy method then?
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 is not pointless.
getExecutor()
will only return something when a build is running. getBuiltOn()
will also return the node when the build is finished when the node with this name still exists. Internally only the name of the node is stored and when you call getBuiltOn()
it searches for the node with the name.
Maybe its time to write some tests with JenkinsRule where a real job is executed on a 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.
Thanks for the explanation.
Based on that I'd still prefer to keep the fallback logic in case somebody somewhere tries to pass a non-running build here.
Maybe its time to write some tests with JenkinsRule where a real job is executed on a node.
Yeah this project definitely needs a heavy makeover (including this class).
I started to port the integ test we do on travis with docker in #36 but there is always something more urgent.
I also need to get more familiar with the jenkins test harness, hopefully #40 will be an opportunity to learn by example
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.
Another thing: how does this compare to the pipeline logic in lines 190-194? Seems to to the same thing but using displayName
?
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 wrong, it will return something like Executor-#0
, but definitely not the host.
For pipelines using getExecutor().getOwner().getNode()
will just get the host where the logstashSend is called, but the build could have run on many different hosts before.
Anyway I'm also looking into a more pipeline like logstash that accepts a block
logstash {
node('label') {
do something
do anotherthing
}
}
but I have to find a way to inject the host after the logstashwriter is initialized.
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.
will just get the host where the logstashSend is called, but the build could have run on many different hosts before.
I get that.
One final question: for now, do you think we should change the pipeline handling to use the getExecutor().getOwner().getNode()
instead of the current executor display name?
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 fixed also the pipeline handling to display the name of the node and not the executor. I also added some integration tests using JenkinsRule.
properly get the node when BuildData is initilaized from a pipeline pump mockito to latest version add integration test, that use Jenkins test harness
Will try to merge this soon. just need to find time to read through the latest commit |
properly get displayname of node (jenkinsci#38)
use the executor of the build to get the node.
builtOn is set too late for us to get the node and we end up using
master
This is a proper implementation that was tried to be fixed with PR #19