Is there a way to get the merge request (particularly the source branch) that caused a particular Push event on the Gitlab Webhook? I want to run a build only once an MR has been merged (hence the push event), but I want to do slightly different things in my Jenkins build based off of the source branch in the MR. Is this doable using a Push event?
I figure one way to do this manually would be to scrape the commit messages from the push event, and parse out any MR commit messages. However, that seems like a very brittle solution.
If it is not doable, could I use the Accepted MR event instead? And if so, is the Accepted event run after the merge happens? Or would I have to do the Merge myself within the job?
According to the Push Events Webhooks Documentation, push events body contains ref field, which is actually the branch to which the push has been performed, i.e the source branch of a merge request (if one has been created for this branch).
If you need more detailed information about the merge request, you may find it useful to consider Merge Requests API. It flexible enough to filter merge requests by source_branch.
Related
I would like to set up a Jenkins based CI system, where the job histories are dynamically managed based on the parameters coming from webhook triggers.
Currently, I can only trigger specific jobs, maybe with applying filters, but it will not handle jobs dynamically.
I aim for a solution, where a parameter (or group of parameters) identifies a job with its own history. If the job history does not exist, it is created automatically.
In the results, I would like to somehow mimic the behavior of the GitHub PullRequest plugin. The problem with it, that it is tightly coupled with GitHub but I need a more generic solution.
I see two marginally different solutions here:
Manage jobs
Jobs can be managed based on the build parameters. The jobs dynamically created and deleted.
Filter builds
The job remains the merged job containing all the Pull request for all the branches, and some UI features able to filter out the different histories from it based on the parameters.
I do not know if any of this is achievable with currently available Jenkins plugins, or if I have to implement something from scratch?
Thank you for any answers!
Actually, I was looking for the Multibranch Pipeline approach, just I didn't know about it yet.
That is actually doing the same that I described for GitHub and BitBucket.
I was lucky as my target was BitBucket.
I have multiple jobs for one Pull requests running on Jenkins.
When a build is done, a comment is posted by a github account to inform it was done, so people get a notification.
It was fine when it was one job per pull request but now it is more spam than anything else.
One simple solution would be to have notifications on build check but it is not provided by github.
Another way would be to get a summary from those jobs when all are done, but I also don't have any idea on how to proceed on this.
Would there be a more cleaner way or a plugin doing this?
You can try using MultiJob plugin.
Create a parent Job and under that add all your jobs. And configure in such a way that, it triggers the parent job which in turn triggers the child job.
This way, it will notify the github only when all the child jobs are completed.
In a JIRA workflow, I would like to automatically execute several transitions one after the other when a certain condition is triggered. How can I do that ?
I have set up a Jira workflow that includes the following statuses
- ToDo (new issue)
- Ready (work planned)
- InProgress (ongoing work)
The normal course of action is to go from ToDo to Ready (is ready transition) and then from Ready to InProgress (start progress transition).
Whatever the current status (ToDo or Ready) of the issue, I would like to move it to InProgress when a branch is created in Bitbucket or a commit is created. That means that if the issue is in the ToDo status, creating a branch or adding a commit should automatically execute is ready and right after that start progress.
Note that I do not want to create any additional transition straight from ToDo to InProgress.
I have tried setting the branch created and commit created triggers on both is ready and start progress. But the best I achieve is to execute a single transition.
Note that I do not want to create any additional transition straight from ToDo to InProgress.
This is basically how Atlassian has designed the workflow and Issue transition logic, you're fighting against the system here.
I don't know if you also consider this as creating an additional transition but what you can do is link the already existing start progress transition to both Ready and ToDo statuses and add the branch hook to that one.
EDIT:
Well, I thought about this a bit more. What you can do is add a Webhook as a Post Function to the is ready transition. You would of course need to build an endpoint that accepts the Webhook and then, after checking that all the conditions pass, take that same Issue and transition it again to InProgress. This endpoint can either be a separate web-server or also a custom JIRA plugin, by the way.
This is what I could come up with limited to JIRA's default functionality. Depending on whether you're running a Server or Cloud instance there might be existing add-ons that provide you with this functionality but I cannot say for certain - you'd need to dig around at Atlassian Marketplace.
If, for example, you have the Script Runner add-on installed you could add a generic Post Function.. function to the issue which can execute any kind of code, you can replace the Webhook endpoint with that function.
With my information, non-admins may not create a new branch. However, is he/she creates one (or gets it created by taking help of someone admin), he/she would still need to get every commit reviewed before merging into branch. Can we avoid this kind of a scenario where pushing something into a less important branch need not go through review process (without making someone an admin)?
I think you should create a subset of branches/references and give permission where everybody can create such branch and can push commit directly.
So create a new reference like refs/heads/feature-[a-zA-Z]* and add Create Reference, Push - with Force Push option to able to delete branches, Push Merge Commit
you can find more info about Access controls there.
We have multiple teams working on one project.Si say if one team completes its development and he/he merges the branch to the Main branch, I want the mailers to be send to different teams so before they doing an upmerge to Main branch they should first downmerge the Main branch to their specific branches.
Create a checkin alert with Server Item Under $/project/Main, and send to whoever needs to know.