Jenkins pipeline jobs integration with bitbucket
TAGS:Jenkins jobs integration with bitbucket SCM
DISCLAIMER In this article I give some workarounds for bitbucket-jenkins integration. It’s not the best solution as far I can see but it solves some of mine problems.
In my work I faced some problems with configuration since I have got only ssh key which was mapped on project, not user/pass service login, so i couldn’t configure some jenins plugins for pipeline job, saddly. Also, bitbucket plugin could not be configured in jenkins pipeline jobs to watch SCM changes, so I had need some workaround for a trigger build too which I’ll show here.
Components:
- Jenkins 2.60.3 (login with admin rights)
- Bitbucket without full admin access
- Project in Bitbucket with developer rights
Bitbucket Configuration
- Login in Bitbucket, go to your project
- Click on Settings -> Hooks
- Find hook ‘Bitbucket server webhook to Jenkins’ in marketplace, request installation from admin
- Configure hook:
- jenins url (should be resolvable from scm)
- skip ssl verification (if you have a self-signed certificate)
- repo clone - ssh or http
Jenkins Configuration
- Login in Jenkins, go to Manage Jenkins - plugins
- Install these plugins:
- Bitbucket branches
- Bitbucket pipeline for BlueOcean
- Scm-api plugin
- Go to Manage Jenkins - System configuration
- In Bitbucket endpoint section choose Manage Hooks - add credentials
- Paste your ssh key, fill in Description and name
- Click Add
Although you will not see created credentials in this drop-down menu you can find them in Manage Jenkins - Credentials menu
Jenkins Trigger job
- Create freestyle job with name ‘Trigger’ or something like that
- Choose Git in Source Code Manage section
- Fill in
- repository URL (ssh://git@scm.company.com:7999/…)
- credentials from previous ‘Jenkins Configuration’ section of tutorial
- Branches to build - i use */master
- Choose these options
- Build when a change is pushed to BitBucket
- Polling for SCM changes ( * * * * * - every minute)
- Click Save
Jenkins pipeline job
- Create pipeline job
- Configure it
- In Build Trigger section choose Build after other projects are built, specify Trigger job
- Click save
That’s it! Now you have simple cicd pipeline between bitbucket and Jenkins pipeline job. However, it is far from ideal - You cannot notify scm about build and stage status and Jenkins is creating some overhead with SCM polling. So if you want some real cool CICD you should have full access to Bitbucket with service account (logit with pass, not ssh-rsa) and Jenkins. And all is going to be supadupa. Cheers!