- Install VirtualBox: https://www.virtualbox.org/wiki/Downloads
- Install Vagrant: https://www.vagrantup.com/downloads.html
- For Windows machines only - run in the terminal:
vagrant plugin install vagrant-vbguest
- Clone or download tutorial git repository https://github.com/omelkova/ci_workshop.git
- Open Terminal and change directory to
box
folder and run Vagrant box:
cd box
vagrant up
- After installation will be finished open the browser and type
http://localhost:7070
, you have to see Jenkins start page: - In order to get the password log in to the VM and navigate to open mentioned file:
vagrant ssh
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy-paste the password
- Customize Jenkins: select "Select plugins to install". Make sure to select following plugins:
- Gradle Plugin
- JUnit Plugin
- Bitbucket plugin
From the main page press create new jobs
button. Enter the job's name and select 'Freestyle project'. Press 'OK'
Scroll down to the 'Build' section, select 'Execute shell' from dropdown menu. Type in the simple shell command echo Hello world
. Press 'Save':
On the main page of our project press 'Build now' button from the left menu:
The build will be scheduled and executed. To see the build result navigate to the 'Build History' on the left menu and click on the blue ball. You will see the console output of the first successful build.
Now lets fail our first job. For that go to the main page for the 'first job' project and press 'Configure'. Scroll down to the 'Build' section and change script to the command which does not exist, for example ech Hello world
, press "Apply".
Run build again by pressing "Build Now" in the "first job" view. The build will fail:
To setup build for the Point of sail(POS) app, first, we need to recall how to use gradle
. Clone your project to the local machine.
- If you have any problems with accessing your code or do not have this project for some reason, you can first
fork
and thenclone
this Bitbucket repositoryhttps://bitbucket.org/omelkova/ci-workshop-pos
:- Create a bitbucket account if you don't have one yet and log in.
- Go to the Project
- Click "Fork"
- Choose any name
- Click "Fork repository"
After cloning the project to the local machine, cd to the project directory and run following gradle commands:
./gradlew assemble
./gradlew test
If you have forked the workshop project - one test should fail.
Create a new job as before.
In the "Source Code Management" section select "Git", enter the URL of your forked project. In the Credentials section click 'Add', add your Bitbucket username and password, click "Add":
Add created credentials:
In the 'Build Triggers' section select the 'Build when a change is pushed to BitBucket' option:
In the 'Build' section select 'Use Gradle Wrapper' radio button. Also tick "Make gradlew executable". Also setup a test
gradle task:
Press "Save".
Go to "Bitbucket job" project and click "Build now". See the console output by selecting "Console Output" in the build view.
To be able to run build on every 'git push' we need to get a Jenkins bitbucket-webhook address. To allow Bitbucket to see our Jenkins server we need to make it available in the Internet. For that we will use ngrok utility (https://ngrok.com/)
- Go to ngrok web page
- Download ngrok for your OS
- unzip to some location
- open the Terminal in this location and run:
./ngrok http 7070
Copy the forwarding URL and !!do not close the console!!: After your Jenkins server become available in the Internet go to your Bitbucket project settings, Webhooks section in the left menu, press "Add webhook". Give any name to your new webhook, paste ngrok forwarding URl+/bitbucket-hook/, press "Save": Note that this webhook become invalid once you will close your terminal with ngrok running. Once you push changes to your Bitbucket repository the Jenkins build will be triggered automatically.
- Login to your Slack account(https://slack.com/)
- Configure the Jenkins integration: https://my.slack.com/services/new/jenkins-ci
- To install this plugin on your Jenkins server
- Go to the main Jenkins page
- Press
Manage Jenkins
on the left panel - Click on
Manage Plugins
and search for Slack in theAvailable
tab. Click the checkbox and install the plugin. - After it's installed, click on
Manage Jenkins
again in the left navigation, and then go toConfigure System
. Find the Global Slack Notifier Settings section and add the provided values: - In the project configurations go to the
Post-build Actions
and addSlack Notifications
, choose events you'd like to be notified about.
press Save
. Now you will receive notifications to the selected slack channel during each build.
- # to Shippable (http://www.shippable.com/) with your Bitbucket credentials
- Click on the button on the top-left corner of the page and select your Bibucket name
- Click on
Enable project
button - Find your project and click on
Enable
- Add
shippable.yml
from this tutorial to the root folder of your project - git add, commit and push. And that is it. Your project's build will be triggered automatically on Shippable and the build status will be displaied on Bitbucket
Build
field.