Is there any way to integrate Bitbucket on cloud and Jenkins On premise - jenkins

I am trying to integrate Bitbucket on cloud and Jenkins on premise, but once I enter the IP of my local Jenkins in Bitbucket cloud it show error URL not valid.
Is there a way to solve this, or do I need to buy Jenkins cloud license?

Your local Jenkins server is not seen by a cloud Bitbucket server because it is an internal server.
You can solve it in one of those alternatives:
Ask your system administrator to expose your Jenkins server with a global IP address along with the Jenkins port (e.g. 8080) so the Bitbucket server will be able to access it. This is not totally secure due.
Activate the Jenkins job that pulls from the remote BitBucket server on time internal - in the Job 'Build Triggers' section check the 'Poll SCM' checkbox and set the cron setting (for example: 'H/15 * * * *' for building every 15 minutes. Notice that it will not build if there were no code changes)

Related

Bitbucket Server Webhook does not trigger Jenkins Pipeline

I have a Jenkins Pipeline that is connected to a Bitbucket Server Repo.
The pipeline is configured with the Bitbucket Jenkins Plugin (version: 223.vd12f2bca5430) and is inside a Docker Container (PORT 8000).
To connect to the Bitbucket Server I have to use a VPN.
I have followed multiple tutorials and articles and failed. This seems a recurrent problem since I have seen multiple questions about this.
When I build the pipeline manually it works fine. It clones the repository and starts the building process but I cannot make the webhook trigger the building process.
Below you can see the configuration.
Jenkins System Settings - Successfull Connection
Pipeline Configuration (Build Triggers)
Pipeline Configuration (Pipeline - Successfull Connection)
When I run the pipeline manually for the first time, the webhook is created in the repository with the following URL: http://localhost:8080/bitbucket-server-webhook/trigger
But when I test the Webhook, it fails everytime a returns the following message:
Unable to connect to the URL specified within the timeout, please check the host and port are correct and that the URL is accessible from the server running this request.
Webhook Config inside Bitbucket Server (Test Fail)
Is this a problem with my Bitbucket Server?
Thank you for your time.

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.

BitBucket Webhook - Unable to connect to Jenkins URL

I am trying to create a webhook in BitBucket to trigger a build in Jenkins, but when I enter my Jenkins URL, and I test the connection, I get the error "Unable to connect to the URL specified, check the host and port are correct." I am using the URL http://localhost:8080/bitbucket-hook/ (with the last back slash included) and I can confirm that in Jenkins, my "Jenkins URL" is set to http://localhost:8080/. In Jenkins, I have installed the plugin "BitBucket Server Integration", and under Configure System -> Bitbucket Server Integration, I have connected to the Bitbucket server (and when I test the connection, it says "Jenkins can connect with the Bitbucket Server", so I am pretty sure Jenkins is configured correctly). I don't have credentials set up in Jenkins for the Bitbucket Server configuration, is this necessary even though when I test the connection, it seems to be able to connect? Is my url for the BitBucket webhook correct?? Is there anything else you can think of that I might not have configured correctly so when I test the connection on BitBucket, it will connect properly?
I just ran through a similar setup, to answer to your questions:
yes, I think you will have to use credentials of a user having admin permissions on the repository upon which you want to create the webhook.
Read below, anyway the Webhook URL I got is in the form < jenkins-url >/bitbucket-server-webhook/trigger
The pipeline
According to my experience, the creation of the Webhook is demanded to Jenkins, you don't have to do anything on your own other than creating a new Pipeline object.
Having set the Bitbucket Server Integration configuration up in fact is not enough for the creation of the Webhook, to do that you have to
create a new Pipeline
flag the Build Trigger "Bitbucket Server trigger build after push"
in the Pipeline section, use as Definition "Pipeline Script from SCM" and fill the other fields according to the configuration you have set before.
Point 3 is saying you are retrieving your Pipeline definition from a file stored in Bitbucket itself, you can also customise the name of the file Jenkins is going to look for (by default this should be Jenkinsfile), and use the "Pipeline Syntax" option to get the snippet of code you will use as step in your Jenkinsfile.
Once you have created your Pipeline in Jenkins, the webhook should appear in the right section in your Bitbucket Server repository.

How to set up an Azure DevOps service connection or endpoint to my localhost Jenkins install

I have Jenkins installed on an Ubuntu 18.04.3 LTS desktop PC on my localhost.
I also have an AzureDevOps repo on which I can successfully run a build, through a Jenkins pipeline job, connecitivity achieved via my AzureDevOps personal access token (PAT).
I am now trying to set up a Jenkins service connection or endpoint in AzureDevOps, to enable me trigger an Azure DevOps pipeline release whenever a Jenkins build completes successfully.
To achieve this in AzureDevOps, I am trying to set up access to Jenkins via a Jenkins service endpoint. The endpoint configuration requires among others, a Jenkins "Server URL" (screenshot below). Not surprisingly, AzureDevOps is unable to connect to my Jenkins instance as it's running on my local machine and therefore not publicly accessible.
Any suggestions on how I can overcome this hurdle would be most appreciated.
How to set up an Azure DevOps service connection or endpoint to my localhost Jenkins install
As we know, in order to receive the service hook notifications, you'll need to expose a port to the public internet.
To expose a port to the public internet, you can try to use the tool ngrok:
ngrok exposes local servers behind NATs and firewalls to the public
internet over secure tunnels.
Please check the document Configure a service hook for PR events for some more details.
Hope this helps.

Publish latest build artifact from "LOCAL" Jenkins to Azure DevOps Release Pipeline?

I have a local Jenkins server running on one of my spare computers (win10). Note that it is not behind any sort of a server and hence is only available within my local network. I have set it up so that it does the continuous fetch from my remote git repo and builds the artifacts and archives them for a successful build. I would like to publish these archives to my AzureDevops Release pipeline. How do I do this? (And yes I have looked through all the tutorials but they assume that I have Jenkins running on a VM somewhere on the cloud).
So far I have had no luck with the tutorials on the web since I donot really have a URL to this instance of Jenkins since it is only available on my local network. I cannot really build these artifacts on a remote Jenkins server, so I am really restricted to using this solution for running the builds.
I am looking to have these archives that Jenkins builds be directly available within my Azure DevOps release pipeline, on every successful build. Thanks for the help!
So since nobody else has answered this I am going to detail what I ended up doing (maybe not the best of the approaches but it works for my setup, suggestions are welcome!).
To interface with the Azure DevOps platform from a local machine you will need to configure a self-hosted agent (based on your specific OS), which will allow you to trigger builds, archive and upload the build artifacts to the Azure DevOps platform. This way you also donot have to poll for SCM changes too (which I think is not that elegant sometimes).
1. So you will need to go through the setup as outlined here for you local self-hosted agent:
Windows: https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops
Linux: https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/v2-linux?view=azure-devops
MacOS: https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/v2-osx?view=azure-devops
NOTE: I have chosen to run the agent as service on windows for my setup
2. Next setup your Jenkins build job how you normally would, with your usual repo access setup. Things to keep in mind are following:
Under "Build Triggers", select the Poll SCM option, but make sure that the schedule is blank, this will make sure that the trigger from your post-commit hook from the agent works. Example setup shown below:
Under "Post-build Actions", make sure that you are archiving the artifacts as required. Example shown below:
3. Now time to setup your project's "Jenkins Service Connection", this can be accessed from the Project Settings tab on the bottom left of you project view in Azure DevOps. Note that this basically helps you self-hosted agent to locate and communicate with the Jenkins instance running locally (or an other network accessible location!). Go under Pipelines -> Service Connections and a new service connection for Jenkins. Note that the trick here is to use the URL for the connection as seen by you local self-hosted agent, which means it can be just any IP (including localhost) that the agent can access normally. Username and password are the same as the ones you setup in Jenkins. Example shown below:
NOTE: You can try to do "Verify and Save" but it will throw an error, so ignore the error or just go ahead and "Save without verification". Also you will have to do this per project, unlike the self-hosted agent setup which is per machine.
4. Now you just need to configure your build pipeline to give jobs to the right agent and pointing to the right service end-point. Now under you build pipeline settings use the agent pool that has the self-hosted agent(s) which can access your build servers. And choose the Jenkins connection that you just created in the above step. The rest of the setup is identical to how you would normally setup your project's build pipeline. An example would be as follows:
NOTE: The key here is the correct "Job name" (this should be the same as the one you have setup in you Jenkins build server instance) and the correct "Jenkins service connection".
5. The rest is straight forward in the sense that you just now need to make sure that you have a step to "Download artifacts" (NOT necessary if you donot want the artifacts on the DevOps platform) & "Publish Artifacts" (this is needed for your release pipeline to see that build artifact and to trigger it too if you want), after your jenkins queue job step. Make sure to setup the correct job directories for download from you local self-hosted agent. Example setup for both the steps:
NOTE: If you are having trouble with the paths for download and publish refer to this link for predefined variables for the self-hosted agents: https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml
6. Now in your release pipeline you should be able to add the artifact sources from you build pipeline. Example shown below:
Now you should be able to get the local artifacts in the cloud on the Azure DevOps platform, in case you cannot use the build agents provided by Microsoft for any reason!

Resources