How to trigger on-premise jenkins job from VSTS using service hook - jenkins

My source code is present in VSTS(cloud) and Jenkins job in the on-premise server(don't have public IP). I would like to implement Continuous integration.
I have a one local build agent. VSTS build definition able to trigger Jenkins job using the agent. But I don't want to create a job. So how to trigger Jenkins job using service hooks.

It's impossible to add local jenkins server to service hook.
Since the local jenkins server (such as http://localhost:8080 or http://{ip}:8080) can not accessed by public network, VSTS can not access to your local jenkins neither. You should make sure the jenkin url is reachable for public network if you need to use service hook.
And if you want to trigger Jenkins build for the event that VSTS build completed, you can add Jenkins Queue Job task the the end of the VSTS build. Detail configuration for this task as below:
Add jenkins service endpoint by clicking the New button -> Input jenkin URL, username and password -> not necessary to verify connection since the public network can't reached -> OK -> input jenkin job name.
Now when the VSTS build pervious tasks are succeed, then jenkins job is triggered.
Note: You should queue the VSTS build by private agent on the same machine where jenkins server installed.

Related

Trigger JMeter tests on a remote system via Jenkins

how can we tell Jenkins to download and run JMeter tests on a remote system rather than from the Jenkins server itself?
My requirement is to create a job in Jenkins to download the latest code from a repo to another system where JMeter is installed and run the JMeter tests on that remote system rather than from Jenkins server itself? I can trigger the tests from Jenkins server itself but unable to connect to remote server and download/trigger the server.
You need to get familiarized with the concept of Jenkins Distributed Builds, it's enough to start Jenkins agent proces on the "remote system" and bind your job to execute on that agent instead of Jenkins master.
With regards to tracking changes in the remote repo check out Generic Webhook Trigger and How to Integrate Your GitHub Repository to Your Jenkins Project articles

Trigger Jenkins Multi-Branch Pipeline from GitLab push

I run a Gitlab and a Jenkins server locally. I connected those two using the gitlab-branch-source plugin. For every repository in gitlab i create a multibranch-pipeline job in jenkins. When a user pushes code, I want the corresponding job to be executed.
I'v tried a solution suggestend in this post and this one. Both of them don't seem to work.
In the gitlab server settings on the jenkins server I've set the check at "Manage Web Hooks". The personal access token which is used for the integration has the scopes "api, sudo".
What else could I try?

Trigger Jenkins job on code commit to Azure repository

I have a Jenkins job running on my localhost:8080. I want to trigger this job automatically whenever there is a commit on Azure repos (Azure DevOps).
Any advise on how I can achieve this?
Thanks
Since Jenkins job running on your localhost:8080. You need to create your self-hosted agents on the local machine which your jenkin server can communicate to. Then you need to create a azure pipeline to be triggered on Azure repos commit and run this azure pipeline on your self-hosted agent. You can check out below workarounds:
Enable Trigger builds remotely on Jenkins
Go the the Build Triggers Tab of your jenkins pipeline configure page--> Then check Trigger builds remotely--> Specify a Token (will be used in the URL)
Define a secret variable to host your jenkins password(eg. password) in azure devops pipeline:
Add a bash task in your azure devops pipeline to run the below curl command
#token must be the same with the token you entered in above step
curl -u $(username):$(password) http://localhost:8080/job/myproject/build?token=anytoken
Targeting your self-hosted agent pool to run your azure devops pipeline on self-hosted agent.
There is another workaround using Jenkins queue job task.
Create a API Token in your Jenkin server.
Go your jenkin account configure page. To create a API token.
Add Jenkins queue job task in azure devops pipeline
Click the Manage link to create a jenkins service connection--> In the newly opened page-->Create Service connection-->Select Jenkins--> Next
Enter the required information. Note: url is your local jenkin server. username is your user account for jenkin server, the Password is the API Token You generated in above step.
Another workaround is to configure the Poll SCM build triggers on your jenkins job. So that the jenkin server will periodically poll the source code and queue the job if there is new commit.
See this thread for more information.

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.

Connection between 2 Jenkins server with out using master slave concepts

How to establish connection between Jenkins jobs hosted on different server with out using master slave concept
I need to send the parameters from one Jenkins server to another both were hosted in different server;
and i need to trigger a down stream project in another Jenkins server
You can use Parameterized remote trigger plugin: https://wiki.jenkins.io/display/JENKINS/Parameterized+Remote+Trigger+Plugin
There are two parts to use this plugin-
Configuration - Go to Manage Jenkins -> Configure System -> Parameterized Remote Trigger Configuration
fill the parameters as appropriate and check the connection using 'validate address' button. If it is validated successfully you are good to go.
Calling a job on remote server - In your job you can add a build step "trigger remote parameterized job".
Fill in the remote server name, poll interval, job name and other parameters.
Now when you will run your job, it will trigger the job on remote server and will check for status on the interval given in poll interval option.

Resources