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

Building all merge requests at a specific time #868

Closed
eriknellessen opened this issue Dec 10, 2018 · 5 comments
Closed

Building all merge requests at a specific time #868

eriknellessen opened this issue Dec 10, 2018 · 5 comments

Comments

@eriknellessen
Copy link

Issue

Context

  • Gitlab plugin version: 1.5.11
  • Gitlab version: 11.5.3
  • Jenkins version: 2.153
  • Job type: Pipeline

Problem description

Describe your problem in a meaningful way:

  • what were you doing (simple push, merge request, MR with fork, ...)
    We have a merge request pipeline that builds all of our merge requests. It works fine. When a merge request is created, or a push is done to the source or target branch, the pipeline is triggered and builds the respective merge request. We also configured triggering via Gitlab merge request comments. This is also working fine.
    Now for performance reasons, we would not like to build on the pushes, but we would like to have a nightly build. Triggering via writing a comment shall still work, so we can trigger builds when necessary.
    We deactivated the push trigger, i.e. we configured "Rebuild open Merge Requests" to "Never". We configured the timer trigger to something like "0 0 * * 1-5" to get a nightly build.

  • what was expected
    All merge requests are built at the time configured (i.e. ad midnight).

  • what occurred finally
    Only one job was started instead of one job for every merge request. The job failed because none of the environment variables were set.

Is there a way to build all merge requests at a specific time?

Thanks in advance for any kind of help!

@omehegan
Copy link
Member

@eriknellessen first, FYI there is currently a bug that breaks the setting of "Rebuild open merge requests" to "never. See #705. Second, without the webhook JSON from GitLab, the plugin has no way to set any of the env vars for source and target branch, etc. So I'm not really sure how you would make this work. Maybe use a Pipeline Multibranch build, so all your branches are automatically detected, and schedule that nightly. But you would have to assume their target branch to merge into was always master, and you would be building branches that didn't yet have MRs. It's probably not ideal. Anyway, this plugin is focused on supporting triggering and build status reporting back to GitLab, neither of which is really encompassed by your request, so I will close this.

@eriknellessen
Copy link
Author

@omehegan thank you very much for your answer!

I can confirm that the plugin did not set the environment variables. Since it was not triggered by the Gitlab webhook, it did not have the information present.

For everyone in the future coming along this issue: We found the following workaround to get our nightly merge requests build:

  1. We extracted sample data from a Gitlab Push webhook run for the master branch (in Gitlab: Settings->Integrations->Select Push webhook->Details for one of the run in the logs)
  2. We setup a Jenkins job that is triggered every night
  3. This Jenkins job takes the data from step 1 and uses it to replay the Gitlab webhook like this:
    echo 'gitlab webhook JSON data here' | curl -X POST -i -H "Accept: application/json" -H "Content-Type: application/json" -H "X-Gitlab-Event: Push Hook" -H "X-Gitlab-Token: secret token here" https://trigger_url_of_your_merge_request_job --data @-

This worked for us, even if the webhook JSON data was static and the master branch changed.

@omehegan
Copy link
Member

@eriknellessen https://github.com/jenkinsci/gitlab-plugin#parameter-configuration might be a simpler solution than your mock webhook replay. Just create parameters with appropriate default values for your job.

@eriknellessen
Copy link
Author

@omehegan thanks for the hint. If I understand the parameter configuration correctly, you can configure variables like gitlabSourceBranch, gitlabTargetBranch etc. This way I could manually create jobs that will build merge requests and I could then just schedule these for any time I like. Anyhow I think I would have to create one for every merge request. Is this correct? My webhook replay workaround builds all merge requests at any time I like without any manual work.

@omehegan
Copy link
Member

@eriknellessen yes that is probably correct, if you are using your webhook replay logic to trigger a bunch of builds, that approach probably makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants