Jenkins github pull request builder do not trigger downstream projects - jenkins

I recently set up github pull request builder on jenkins and it works well when I commented the trigger phrase on the PR. But when I tried to run multiple jobs by setting the downstream upstream relationship, I met this problem which is jenkins triggered the job job A set up by pull request builder as normal, but wouldn't trigger the downstream job job B when job A has finished.
Here are some of settings:
In job A: just everything on the instruction page of the github pull request builder
In job B: Under Build Triggers section, I checked Build after other projects are built and set the projects to watch to be job A, and checked Trigger only if build is stable (Nothing about github pull request builder on job B)

Try doing this from the upstream project, instead. From the upstream project configuration, Add post-build action --> Build other projects, then enter the name of the project to build.

Related

How to update gitlab Merge Request build status (pipeline status) when using Jenkins and the pipeline was previously canceled/deleted?

We set up Gitlab with Jenkins integration, by using Jenkins Gitlab plugin and trigerring Jenkins webhooks (regular Pipeline type job) on gitlab Merge Request events (configured in Gitlab->Repo->Integrations) and we are successfully displaying the job build status on the Merge Request page (by using updateGitlabCommitStatus in the pipeline) - it is displayed as a status of some pipeline, which as I understand, is created and associated with the last commit in the source branch.
At some point, I canceled this pipeline from the MR page and after that, closed and reopened the MR, thus re-triggering the build.
Unfortunately, after cancelling the pipeline, the latest build job statuses were not reflected nor in the MR, nor in the pipeline itself. In the pipeline page it wouldn't even display the newest jobs running in jenkins.
I tried deleting this specific pipeline (via curl - we are using gitlab 12.3, which doesn't allow deleting pipelines via GUI) and creating a new Merge Request (same branch, same commit), hoping that a new pipeline would be created in this case, but nothing. It seems that I have no means to display build status again for this specific commit.
Any suggestions how to overcome this?
Thanks in advance!
I have a similar case and the only way to do this is to re-run the pipeline from GitLab... You have to enter to the integrations and there you should look for all request sent to the Jenkins. Once you locate the correct one, you click on resend and it should give you the correct status.
For my observations, the update GitLab status command only work when it is invoked from a webhook.

How to trigger jenkins job that execute automation test scripts when code is pushed in development server?

I am new to Jenkins. I have development code repository at bitbucket and another test script code repository at bitbucket. Now I have setup a Jenkins job by linking test code repository. Is there any way to trigger a build when code is pushed in develop repo?
I tried many times by pushing change in develop repo, but it does not triggers the jenkins job.
You can configure the Jenkins trigger as an SCM poll.
You will have to enter a cron expression for the polling time period, like:
*/5 * * * *
This means polling from 5 to 5 minutes. If any change is detected, then the build is triggered.
You can add the BitBucket Plugin to your Jenkins instance. It will allow you to configure a webhook in BitBucket that will then trigger any Jenkins job listening for that webhook. The plugin's page has a detailed breakdown, but the basics are;
In your repo in BitBucket, create a new Webhook using your Jenkins' url. I believe the url is generally http://[your jenkins url]/bitbucket-hook/
Make the trigger a repo push.
In your Jenkins job, check the box "Build when a change is pushed to BitBucket" under the Build Triggers section.
Now any time you commit to the repo you created the Webhook on, that Jenkins job will be run.
You can also limit what branches trigger commits by parameterizing your Jenkins build to ignore certain branches / keywords / etc if that's something you need for your specific project.
You can use webhooks to trigger build automatically. There are few options how to use it. See the following articles: this, this and this.

github pull request builder workflow with Jenkins

I am completely new to DevOps and couldn't fix the builder and merger plugin flow.
I have 2 Jenkins jobs.
job A: pipeline with build trigger as GitHub Pull Request Builder.
job B: freestyle project which is triggered on the successful completion of job A (uploading artifacts to Nexus etc.)
Job A should be triggered automatically once pull request is created in GitHub but it doesn't work at all. Below is from GitHub.
[GitHub says "CI setup hasn't been done yet"][1]
Continuous integration has not been set up
Even if i build Job A manually, Job B doesn't merge.
Not sure what to look into.

How can I use Jenkins in MS VSTS to build Pull Requests?

I tried to connect my Jenkins server to VSTS repo by following this Link.
https://blogs.msdn.microsoft.com/devops/2017/04/25/vsts-visual-studio-team-services-integration-with-jenkins/
However, the options are different from the tutorial.
There is no way to set a rule for Pull Request, which is what I am trying to do.
I set a new build definition to make the Jenkins build work on every commit, but doesn't work for Pull Request.
To queue Jenkins job for VSTS pull request build validation, you can follow below steps:
Create a job in Jenkins
First, you need to create a job in Jenkins. If you have already create, then skip this step.
Create and configure build definition for PR build validation
Seems you already created a build definition named Jenkins, then add
Jenkins Queue Job task.
If you didn’t configure your Jenkins as an endpoint in your VSTS project, you can click New button to specify server URL, username and password to login the Jenkins.
Then specify the Jenkins job for queuing.
Note: If your Jenkins setup as a local server (the url as http://localhost:8080), then you need to queue VSTS build by private agent which also located in the same machine.
Add build policy as the target branch policy
In the build policy, you can set the Trigger as Automatic, the Policy requirement as Required, and the Build expiration is Immediately.
Now when pull request is created or updated for merging into the target branch, VSTS build will be triggered immediately, and the Jenkins job will also be queued during VSTS build.

a Jenkins job for every pull request

I want to do a very simple thing - for every new pull request that is being created under my repo, I want to create a new jenkins job with similer configuration (run some batch), that will checkout the branch that is being merged (not the destination branch).
I will also like to delete this job after the pull request is approved, but that's not as important.
How do I do that? Every jenkins plugin that I found creates jobs for all my branches, or for a specified list of branches, instead of just for new ones or just unmerged pull requests
Here is one way you could solve this:
Create a template job containing the logic you want to do for each new branch (i.e. run some batch).
Create a job that is started for every new pull request in your repo. You could probably do this with the Script SCM Plugin using a short groovy script.
Inside this triggered job, clone the job in #1 using the Jobcopy Plugin. Replace any strings (e.g. git url) with whatever is needed to get the job working.
You could write another job that is triggered via the Script SCM Plugin when a branch needs to be deleted. You can remove it using the Groovy Postbuild Plugin.
OK I finally succeseeded, and it was WAY EASIER then I thought. I found a jenkins plugin called "Bitbucket pullrequest builder plugin", and it makes it incrediblly ease to build jobs for pull requests. The only thing is that I couldn't make it work with any OAuth consumer, and had to give it my own credentials. But other then that it works beautifully.
This is very similar with what we did in our team (We have more than 10 development branches and also a lot release branches)
I think the easiest way is as follows:
Plugin should be used:
gerrit trigger plugin
Used to get triggered when there is new commit come in
job dsl plugin
Used to generate the jobs based on the dsl script
build flow plugin
Used to define the execution flow
Create a Jenkins build flow job "EntryPoint" (This job will be triggered if there is a new commit push for review)
Create the a job generator job (This job will invoke the job dsl script to generate the template jobs based on the input parameter, such as branch)
Create a new job to do the cleanup work or as Daniel said, you can do it with groovy post build
Inside the build flow job, a simple flow as follows
//Get current branch from gerrit trigger plugin
def currentBranch = params[GERRIT_BRANCH]
//Invoke job generator job and pass the branch info to it
build ("job_generator",BRANCH:currentBranch )
//Invoke the generated job by job_generator
build("$currentBrnch_Build")
//Remove the generated job
build("CleanUpJob")

Resources