DEV Community

Mehak Fatima
Mehak Fatima

Posted on

Trigger Bitrise Build Using Bitrise Api

Pre-Requisite:

  • what is Bitrise.
  • How to use Bitrise.

Motivation:
Now I can trigger bitrise builds from anywhere according to my need i am not bind.

Let’s Start…

Steps:

const axios = require('axios');
const {lastGitCommit} = require('./Git');
const buildArgs = process.argv.slice(2);
// we have to extract first index of perameters buildArgs[0]
const headers = {
  Authorization: 'Auth Token',
};
const gitCommit = [];
const gitInfo = async () => {
  const response = await lastGitCommit();
  // console response and check if anything else you need.
  gitCommit.push(response);
  return response;
};
gitInfo();

setTimeout(function () {
  const data = {
    hook_info: {
      type: 'bitrise',
      triggered_by: 'Bitrise BUild',
    },
    build_params: {
      branch: 'master',
      commit_message: gitCommit[0].subject,
      commit_hash: gitCommit[0].hash,
      workflow_id: 'android',
    },
  };
  const post = async (url, data, headers) => {
    const payload = {
      method: 'post',
      url: url,
      headers,
      data,
    };
     const response = await axios(payload);
     return response;
  };
  const triggerNewBuild = async () => {
    let response;
    try {
      response = await post(
        'https://api.bitrise.io/v0.1/apps/slug_num/builds',
        data,
        headers,
      );
    } catch (exception) {
      error(`Error fetching All builds${exception} `);
    }
    return response;
  };
  triggerNewBuild();
}, 5000)
Enter fullscreen mode Exit fullscreen mode
  • Run file with the command Node Android.js.

Top comments (0)