Using Bluemix DevOps with a local git repository

5 min read

By: David Provan

Using Bluemix DevOps with a local git repository

I have long been a fan of the DevOps pipeline available on the bluemix platform.  I was impressed by the original jazz version and the migration to the new pipelines was an enjoyable upgrade on what was presented before.  My issue had always been that my source code needed to be managed on bluemix git repositories.  As part of a larger practice we had a git repository server behind our firewall and I couldn’t get the pipeline to connect to it.

This seemed solvable and it turns out it was incredibly simple to achieve. Listed below are the steps to enable auto deploy with your local git repository to the pipeline.

Principles of Approach

This approach utilizes the fact that git is a distributed version control system, at it’s core the approach uses mirroring of repositories to connect our local git server to one inside bluemix and the pipeline operates off that.

Principles of Approach

In our build environment we have a git server running on an IBM Internal Cloud system, we are running GitLab on this as well, and we have a bluemix app that we want to be updated using the Bluemix pipelines from new commits on the master branch of this repository.

How to re-create

If you don’t have a git project already on the bluemix git server then create one,  additionally you will need to create an HTTP token with api access to allow us to push content up over http to the repository.

Step 1 – Create your access token on Bluemix Git Server

To create the token:

  1. Access https://git.ng.bluemix.net/

  2. In the top right select your avatar and select “Settings”

  3. Select “Access Tokens” in the navigation

  4. Enter a name for the token and set an expiry (we routinely set our for 1 year from today)

  5. Check the box next to “api” to give the new token api access level

  6. Click the “Create personal access token” green button

  7. A new screen will appear showing the token, take note of that token and keep it somewhere safe

  8. Note the Token Name and the API Token value, you will need them in Step 3.

Step 2 – Setup target project on the Bluemix Git Server

If you have a project on the Bluemix git server you want to mirror to then proceed to the next step, otherwise follow the steps below:

  1. Access https://git.ng.bluemix.net/

  2. Click the “New Project” button on the right hand side

  3. Name the project and set your access level (we usually choose private for code intellectual capital reasons), we typically will name the project in bluemix the same as our local for ease of use

  4. Click the “Create Project” button at the bottom of the page

Step 3 – Setup mirroring to the Bluemix Git Server

  1. On your local gitlab server open the Project you want to mirror

  2. Click on “Settings”

  3. Click on “Repository”

  4. Expand out “Push to a remote repository”

  5. Check the box next to “Remote mirror repository”

  6. In the Git repository URL enter the following (using the info from Step 1 instruction 8):https://<name of your token />:<secrect token from step 1 />@git.ng.bluemix.net/<path to your repo />.git

  7. Click “Save changes”

  8. Request to “Update Now” to sync the repositories

Step 4 – Setup the Pipeline

The pipeline is set-up in the same traditional way. Create a new DevOps pipeline and pick the names you want to provide to that pipeline.

The important part is when you select the associated repository under Source Code.  We selected the Bluemix Git server (git.ng.bluemix.net) as our Git Provider and selected the mirrored project as the source.

The configure your build and deploy stages as suggested for your given implementation.  We were using gradle and liberty so had the gradle command in build and the standard cf push in the deploy phase.

Step 5 –  Test

The test is to now commit to the master branch of your local repository, your Local Gitlab should push that change to the bluemix mirror inside 5 minutes and then the trigger should head to the DevOps pipeline to push the deploy.

Conclusion

I hope this helps you configure and take advantage of the Bluemix DevOps tools with a  local git repository you may have.  If you’re not using GitLab there are standard commands to mirror a git repo e.g. “git push –mirror git@example.com/new-location.git

If you’re not familiar with GitLab you can use the Community Edition for Free, information for that is available at https://gitlab.com/gitlab-org/gitlab-ce

Be the first to hear about news, product updates, and innovation from IBM Cloud