Skip to content

Commit

Permalink
Fail project if set build number fails
Browse files Browse the repository at this point in the history
  • Loading branch information
peabnuts123 committed Feb 10, 2019
1 parent ca4d685 commit 4213e2e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
1 change: 1 addition & 0 deletions scripts/build/errorCodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export default {
CREATING_NPMRC_FAILED: 107,
PUBLISH_FAILED: 108,
REMOVE_BUILT_TESTS_FAILED: 109,
SET_BUILD_NUMBER_FAILED: 110,
COPY_PROJECT_TO_PUBLISH_DIRECTORY_FAILED: 111,
};
61 changes: 35 additions & 26 deletions scripts/build/setBuildNumber.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
import * as azdev from 'azure-devops-node-api';

import { getBaseBuildConstants } from "../util";
import ERROR_CODES from './errorCodes';


(async () => {
const buildConstants = getBaseBuildConstants();
const orgUrl = "https://dev.azure.com/peabnuts123";
const token: string = process.env.AZURE_DEVOPS_TOKEN as string;
const definitionId = parseInt(process.env.SYSTEM_DEFINITIONID as string, 10);
const projectName = process.env.SYSTEM_TEAMPROJECT as string;
const branchName = process.env.BUILD_SOURCEBRANCHNAME as string;
const buildId = process.env.BUILD_BUILDID as string;

const authHandler = azdev.getPersonalAccessTokenHandler(token);
const connection = new azdev.WebApi(orgUrl, authHandler);
const build = await connection.getBuildApi();
const buildDefinition = await build.getDefinition(definitionId, projectName);

let version = buildConstants.packageJson.version;
if (branchName !== 'master') {
version += `-${branchName}b${buildId}`;
}
try {

const buildConstants = getBaseBuildConstants();
const orgUrl = "https://dev.azure.com/peabnuts123";
const token: string = process.env.AZURE_DEVOPS_TOKEN as string;
const definitionId = parseInt(process.env.SYSTEM_DEFINITIONID as string, 10);
const projectName = process.env.SYSTEM_TEAMPROJECT as string;
const branchName = process.env.BUILD_SOURCEBRANCHNAME as string;
const buildId = process.env.BUILD_BUILDID as string;

buildDefinition.variables = {
...buildDefinition.variables,
VERSION: {
allowOverride: false,
isSecret: false,
value: version,
},
};
const authHandler = azdev.getPersonalAccessTokenHandler(token);
const connection = new azdev.WebApi(orgUrl, authHandler);
const build = await connection.getBuildApi();
const buildDefinition = await build.getDefinition(definitionId, projectName);

await build.updateDefinition(buildDefinition, definitionId, projectName);
let version = buildConstants.packageJson.version;
if (branchName !== 'master') {
version += `-${branchName}b${buildId}`;
}

buildDefinition.variables = {
...buildDefinition.variables,
VERSION: {
allowOverride: false,
isSecret: false,
value: version,
},
};

await build.updateDefinition(buildDefinition, definitionId, projectName);
} catch (e) {
console.error(e);
console.error("Failed to set build number. ");
process.exit(ERROR_CODES.SET_BUILD_NUMBER_FAILED);
}
})();

0 comments on commit 4213e2e

Please sign in to comment.