-
Notifications
You must be signed in to change notification settings - Fork 38
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
Lookup previous build using build id and re-use any parameters #236
Conversation
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.
Taking generic webhook plugin out of the picture here, did re-populating parameters work before or was that just missing?
That was always missing. The existing implementation launches a new build from the job id stored in the external_id checks field. I'm guessing this ONLY would have worked using multi-branch? I believe this PR would extend the use-case of this plugin to a regular pipeline. However, the reason I mentioned generic-webhook-plugin is because I don't know what other context parameters would be used when initially triggering a job from jenkins. We are migrating to github from an environment (bitbucket) where we utilized parameters extensively. Generic-webhook-plugin allows us to keep these parameters and map the webhook payload to the existing parameters we have making our migration path much simpler. |
concept seems fine, if you can fix the build and testing passes we can take it |
Absolutely, will do. |
Looking at the In my mental model, a check would ALWAYS be published from within a specific run/build of a job, not the job itself so this distinction is throwing me off a bit. Can anyone help enlighten me as to what I'm missing here?
|
I think the initial Queued check is done before the run exists and it's set to the job. @XiongKezhi do you remember? |
I think I see the difference between QUEUED and the other status checks here: https://github.com/jenkinsci/checks-api-plugin/blob/0a83c62e4f728c6b57018dc36b3fa23ac8850c0f/src/main/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisher.java#L143. QUEUED seems to use the fromJob() as you mentioned so thanks for that pointer. Digging deeper it seems that this plugin has two functions to resolve the SHA used for the check, one for the job and one for the run: Line 114 in 1c4caf9
What I can't quite wrap my head around is how the function which gets the SHA from the job is guaranteed to match the SHA from the run within a Github pull request context. This is especially confusing when the Job's HEAD/SHA is dynamic based on an incoming parameters like ours. Can you give an example of where the Run/Job configuration is guaranteed to have the same SHA? Appreciate the guidance here. |
…parameters from original build.
d887352
to
0878172
Compare
Might have answered my own question by continuing to dig. Using the In this case, I can understand how both the job and the run would have the same hash since the job is configured using the PR branch. |
0878172
to
77a475d
Compare
I don't understand your question to be honest. But hopefully you figured out what you needed |
@Test | ||
void shouldThrowExceptionWhenHeadBranchMissingFromPayload() throws IOException { | ||
assertThatThrownBy( | ||
() -> { | ||
new CheckRunGHEventSubscriber(mock(JenkinsFacade.class), mock(SCMFacade.class)) | ||
.onEvent(createEventWithRerunRequest(RERUN_REQUEST_JSON_FOR_PR_MISSING_CHECKSUITE_HEAD_BRANCH)); | ||
}) | ||
.isInstanceOf(IllegalStateException.class) | ||
.hasMessageContaining("Could not parse check run event:"); | ||
} | ||
|
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.
Bad merge by the looks of it, the behaviour was changed in f35f09a
@Test | |
void shouldThrowExceptionWhenHeadBranchMissingFromPayload() throws IOException { | |
assertThatThrownBy( | |
() -> { | |
new CheckRunGHEventSubscriber(mock(JenkinsFacade.class), mock(SCMFacade.class)) | |
.onEvent(createEventWithRerunRequest(RERUN_REQUEST_JSON_FOR_PR_MISSING_CHECKSUITE_HEAD_BRANCH)); | |
}) | |
.isInstanceOf(IllegalStateException.class) | |
.hasMessageContaining("Could not parse check run event:"); | |
} |
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.
Have you manually tested this works via ngrok, smee or something?
Code looks good apart from the minor build issues
Yes, we have this installed in a jenkins instance and it is working as we expect. |
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.
Looks good pending a green build, (builds are unstable currently due to jenkins-infra/helpdesk#2733)
Codecov Report
@@ Coverage Diff @@
## master #236 +/- ##
============================================
+ Coverage 80.19% 80.49% +0.30%
- Complexity 168 170 +2
============================================
Files 16 16
Lines 520 528 +8
Branches 47 49 +2
============================================
+ Hits 417 425 +8
Misses 81 81
Partials 22 22
Continue to review full report at Codecov.
|
Can you check the build please, 2 pmd issues |
74dd2bc
to
8a464d6
Compare
Can this be merged at this point? |
When using the generic-webhook-plugin, webhook payloads are parsed (via jsonpath) and injected into the original build as parameters. When re-requesting a check from github, we need the ability to look up the parameters of the original build so that the build has the parameters from the original build. Otherwise empty/default parameters would cause the build to fail (even which git hash we check out is driven by a parameter).
In order to accomplish this, we use the jenkins externalized build id as the external_id when publishing the check. When the check is re-triggered, we are able to look up the original build and re-inject the parameters.
I believe this may be a generic solution to #223. Our issue is that instead of a single parameter, we have 10-20 parameters so we needed a solution which is able to re-populate those parameters.
I realize there are risks with changing the mechanism by which we look up the job. What I would like some feedback on is whether this change should be compatible with the original intent of the plugin (via a multibranch pipeline). There is also a risk that the original build has fallen off the history and can no longer be looked up, but it's unclear to me how big of an issue that would be in practice.