Trigger Bitrise Build Using Bitrise Api
Mehak Fatima
Posted on April 13, 2022
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:
- Create Android.js file inside the project.
- Collect Authorization token from bitrise https://devcenter.bitrise.io/api/authentication/ .
- Import latest git commit method .
- Add following code inside the file.
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)
- Run file with the command Node Android.js.
💖 💪 🙅 🚩
Mehak Fatima
Posted on April 13, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.