DEV Community

Mehak Fatima
Mehak Fatima

Posted on

How to Trigger Bitrise Build from Bitbucket Pipeline?

Hi fellow coders!
In my recent project, I felt the need to trigger Bitrise build from Bitbucket Pipeline. I hope the first question that comes in your mind would be what's the reason behind that.
so Let's see...

Motivation:
Let's suppose you have a project "abc" which contains the 3 different sub projects or folder in it.(e.g mobile, web, server)and you want to use same bitbucket repo for these 3 projects. But whenever you push some changes in web or server's folder it triggers the bitrise mobile's build which is not required.
Basically the reason behind that is whenever bitrise feels any change in bitbucket repo it starts automatic(trigger) build.
In bitrise Enable selective builds feature is not currently available for bitbucket repo.
"So our target is to run mobile build when you find changes in mobile's folder only."

Solution:
we are going to use Bitrise's api instead of automatic Bitrise’s triggers and we will hit Bitrise api endpoint through Bitbucket pipeline.

Let's start...
Trigger Bitrise using Postman (optional):
we are using postman here for testing bitrise api

const data = {
    hook_info: {
      type: 'bitrise',
      triggered_by: '',
    },
    build_params: {
      branch: 'master',
      commit_message: "",
      commit_hash: "",
      workflow_id: 'primary',
    },
  };
//Now post the api
Enter fullscreen mode Exit fullscreen mode
  • Open bitbucket.yml file of your project in your editor.
  • For testing purpose, lets first create a step for Mobile Build in Bitbucket pipeline using node image.
- step:
          name: Run Android Build
          image: node:10.15.3
          script:
            - echo "Going to trigger Android Build"
Enter fullscreen mode Exit fullscreen mode
  • If Pipeline run successfully after step 2, proceed further. If not, there is something wrong with yml file.
  • We will apply Change set condition on step (the step should run only if we make changes in this folder) .
- step:
          name: Run Android Build
          image: node:10.15.3
          condition:
            changesets:
              includePaths:
                - "mobile/**"
          script:
            - echo "Going to trigger Android Build"
Enter fullscreen mode Exit fullscreen mode
 - step:         
          name: Run Android Build
          image: node:10.15.3
          condition:
            changesets:
              includePaths:
                - "mobile/**"
          script:
            - echo "Going to trigger Android Build"
            - npm install axios
            - npm install git-last-commit
            - cd mobile/MobileBuilds
            - node Android.js $BITRISE_TOKEN
Enter fullscreen mode Exit fullscreen mode

Top comments (0)