-
Notifications
You must be signed in to change notification settings - Fork 52
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
[FIX] If cleanup should be able to mark build as failed, it needs to be run before finalizers #29
base: master
Are you sure you want to change the base?
Conversation
…be run before finalizers
@olivergondza, @oleg-nenashev what do you think about it? |
I agree this is what need to be done in order to implement the fail the build functionality. But, it can cause other publishers to misbehave as the workspace cleanup can run before then purging the data they want. What makes this even more surprising is (IIRC) the order of publisher execution in is not the order of their declaration. To me it seems more important to perform cleanup as the very last thing than implementing fail the build functionality. I am actually starting to think the method is implemented the way it is for a reason. |
@olivergondza In our environment it works as expected. So, it looks like order of execution is same as order of declaration. Maybe somebody from Cloudbees can help us to understand guarantees. From code perspective you have a list of publishers, but when it performs method accepts any Without my PR |
It should not be a case for all more or less modern Jenkins core versions. On very old Jenkins cores (1.400?) there was a checkbox-based selection of post-build actions. In such case there was no order of definitions. If the job has been migrated from such old core version and never saved afterwards, then Publisher execution order may differ from the order in UI. But it's a not realistic case IMHO |
Actually, the Build status change behavior changed in Jenkins 1.584. jenkinsci/jenkins@28dfd90 . So this plugin likely behaves incorrectly after it. We already had such issues in other plugins (I do not recall which ones). So I agree that the fix is required in WS Cleanup plugin. The proposed one is not ideal since the plugin behavior may differ depending on the advanced setting. Maybe switching to |
Plugin behaviour would differ depending on the advanced setting anyway ;) |
@oleg-nenashev, @Jimilian, I gave it a try and publishers are not executed in the order they are declared. There is some
To my observation, the implementations where So if there is a publisher that rely on workspace and declare |
@olivergondza yes, you are right that if user has two plugins: But for me it's clear that nobody can rely on data from workspace after finalisers. It could be only some pure |
Note that there is no link between build result being computed and workspace being available aside from this PR so I do not think you can assume there are no notification plugins that rely on workspace. Quick greping through source reveals there are such plugins: https://github.com/jenkinsci/ivy-plugin/blob/master/src/main/java/hudson/ivy/IvyBuildTrigger.java or https://github.com/jenkinsci/email-ext-plugin/blob/master/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisher.java |
@olivergondza, if cleanup fails I want to see how build fails, because in this case I will catch failure as soon as possible. Otherwise, I need to investigate root cause - analyse node history, etc. Last time we spent 20 hours to find root cause. Only because developer who introduced invalid character got success result.
It's true. I hope than Cloudbees can fill this gap. Otherwise I can't see any reason to split publishers in two groups. Of course, it's your plugin and your rules, but guy who developed |
Definitely.
The reason is the later group can rely on build status being final. It has nothing to do with workspace.
As I said, it is sane a not uncommon assumption and it is our job, as ws-cleanup contributors, to deal with that. Let me dig into this a little bit to see what can be done to preserve the feedback to the users. |
One more problem with running this before finalized is the post build step is making decision to clean or not to clean based on the build status that can change later. Additionally, when workspace is cleaned asynchronously (which is what we want to be turned on by default) there is no way to inform people something is wrong. I am leaning towards representing the failure to cleanup afterwards in some other way. Failing the next build perhaps? |
One more though, once post build step throws an exception we must expect the WS is in inconsistent state from the users perspective (it was not wiped out or cleaned selectively as requested) and should not be reused by future builds. An alternative approach would be to wipeout (rename and delete asynchronously) the workspace if configured cleanup fails. That should eliminate most problems with configuration (custom command does not work for instance) but still can fail in case of permissions, etc. Those problems will be reported to admin via #28 (there are danging directories occupying space somewhere) but future builds will not be affected. @Jimilian, WDYT? |
I think user should be able to make a choice (that's why in my first commit I re-used option 'fail if cleanup failed'). Because in our environment priorities are quite simple:
Also, different users prefer different plugins and it's hard to predict all ways of working. If you agree, I can introduce global option (from Jenkins config) that changes value of You are right that after such issues workspace is in inconsistent state and it doesn't make sense to keep it. So, user can do several things even now:
I think asynchronous cleaning up before build starts is better in this case, because Extremely important: I don't expect any hidden magic on plugin side. Only some general recommendation from contributors. Otherwise, it could create new (unexpected) bugs/performance issues. |
In general there is no way to tell if failure to delete the workspace is a problem of infrastructure, job configuration or the code that is built.
Right, that should be fixed in #28.
the problem is that user needs to think ahead. I would love to be more helpful than that. |
So, according docs:
So, if
needsToRunAfterFinalized
returnstrue
.Publisher
is not able anymore to change build result (code from last Jenkins, but it's quite old) and any negative result would be just logged:Unfortunately, I failed to write test for this fix, so, if you have any suggestion how to perform it - it would be nice. But I tested it manually and it works as expected - marks build as failed if needed.