Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let commitId = tl.getInput("version");
let debugOutput = tl.getVariable("system.debug");
debugOutput = debugOutput || "false";
let isDebugOutput: boolean = debugOutput.toLowerCase() === "true";
// print what is supplied by the user
tl.debug(`endpoint: ${JSON.stringify(auth)}`);
tl.debug(`definition: ${definition}`);
tl.debug(`branch: ${branch}`);
tl.debug(`downloadPath: ${downloadPath}`);
tl.debug(`versionSelector: ${versionSelector}`);
tl.debug(`commitId: ${commitId}`);
tl.debug(`debugOutput: ${debugOutput}`);
if (!downloadPath || downloadPath.length === 0) {
downloadPath = tl.getVariable("System.DefaultWorkingDirectory");
}
console.info(`Cleaning ${downloadPath}`);
CleanFolder(downloadPath);
console.info("Done");
tl.debug("Finding repository url");
let gitApi = new GitApi();
let repoUrl = await gitApi.getRepoUrl(endpointUrl, definition, token);
console.info(`Repo Url: ${url.format(repoUrl)}`);
commitId = commitId || "";
if (commitId === "") {
console.info("Identifying commit id");
if (versionSelector === "latestDefaultBranch") {
tl.debug("Finding commit for default branch");
const version: string = `1.0.0-${hash}`;
let accessToken: string;
let feedUri: string;
const publishedPackageVar: string = tl.getInput("publishedPackageVar");
const versionRadio = 'custom';
let internalAuthInfo: auth.InternalAuthInfo;
const toolRunnerOptions = artifactToolRunner.getOptions();
let sessionId: string;
// getting inputs
serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false);
packageName = tl.getVariable('Build.DefinitionName')
.replace(/\s/g, "")
.substring(0, 255)
.toLowerCase();
feedId = tl.getInput("feedList");
// Setting up auth info
accessToken = pkgLocationUtils.getSystemAccessToken();
internalAuthInfo = new auth.InternalAuthInfo([], accessToken);
toolRunnerOptions.env.UNIVERSAL_PUBLISH_PAT = internalAuthInfo.accessToken;
// creating session
const useSessionEnabled = tl.getVariable("Packaging.SavePublishMetadata");
if (useSessionEnabled) {
let packagingLocation: string;
function _createExtractFolder(dest?: string): string {
if (!dest) {
// create a temp dir
dest = path.join(tl.getVariable("Agent.TempDirectory"), "artifactTool");
}
tl.mkdirP(dest);
return dest;
}
export async function doesPackageExist(hash: string): Promise {
const feedId = tl.getInput("feedList");
// Getting package name from hash
const packageId = tl
.getVariable("Build.DefinitionName")
.replace(/\s/g, "")
.substring(0, 255)
.toLowerCase();
const version = `1.0.0-${hash}`;
const accessToken = pkgLocationUtils.getSystemAccessToken();
const collectionUri = process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI;
let instance: string = "";
const legacyRegex = /https:\/\/(\S+).visualstudio.com\S+/g;
const newRegex = /https:\/\/dev.azure.com\/(\S+)\//g;
const legacyUrl = legacyRegex.exec(collectionUri);
const newUrl = newRegex.exec(collectionUri);
function _logTwineAuthStartupVariables() {
try {
const twineAuthenticateTelemetry = {
"System.TeamFoundationCollectionUri": tl.getVariable("System.TeamFoundationCollectionUri"),
};
telemetry.emitTelemetry("Packaging", "TwineAuthenticate", twineAuthenticateTelemetry);
} catch (err) {
tl.debug(`Unable to log Twine Authenticate task init telemetry. Err:( ${err} )`);
}
}
private static CreateBuildSessionRequest(
feedId: string,
buildId: string
): SessionRequest {
let buildData = {
"System.CollectionId": tl.getVariable("System.CollectionId"),
"System.DefinitionId": tl.getVariable("System.DefinitionId"),
"System.TeamProjectId": tl.getVariable("System.TeamProjectId"),
"Build.BuildId": buildId,
"Build.BuildNumber": tl.getVariable("Build.BuildNumber"),
"Build.DefinitionName": tl.getVariable("Build.DefinitionName"),
"Build.Repository.Name": tl.getVariable("Build.Repository.Name"),
"Build.Repository.Provider": tl.getVariable("Build.Repository.Provider"),
"Build.Repository.Id": tl.getVariable("Build.Repository.Id"),
"Build.Repository.Uri": tl.getVariable("Build.Repository.Uri"),
"Build.SourceBranch": tl.getVariable("Build.SourceBranch"),
"Build.SourceBranchName": tl.getVariable("Build.SourceBranchName"),
"Build.SourceVersion": tl.getVariable("Build.SourceVersion")
};
var sessionRequest: SessionRequest = {
feed: feedId,
source: "InternalBuild",
data: buildData
};
return sessionRequest;
private static CreateBuildSessionRequest(
feedId: string,
buildId: string
): SessionRequest {
let buildData = {
"System.CollectionId": tl.getVariable("System.CollectionId"),
"System.DefinitionId": tl.getVariable("System.DefinitionId"),
"System.TeamProjectId": tl.getVariable("System.TeamProjectId"),
"Build.BuildId": buildId,
"Build.BuildNumber": tl.getVariable("Build.BuildNumber"),
"Build.DefinitionName": tl.getVariable("Build.DefinitionName"),
"Build.Repository.Name": tl.getVariable("Build.Repository.Name"),
"Build.Repository.Provider": tl.getVariable("Build.Repository.Provider"),
"Build.Repository.Id": tl.getVariable("Build.Repository.Id"),
"Build.Repository.Uri": tl.getVariable("Build.Repository.Uri"),
"Build.SourceBranch": tl.getVariable("Build.SourceBranch"),
"Build.SourceBranchName": tl.getVariable("Build.SourceBranchName"),
"Build.SourceVersion": tl.getVariable("Build.SourceVersion")
};
var sessionRequest: SessionRequest = {
feed: feedId,
source: "InternalBuild",
data: buildData
};
return sessionRequest;
}
}
public static CreateSessionRequest(feedId: string): SessionRequest {
var releaseId = tl.getVariable("Release.ReleaseId");
if (releaseId != null) {
return ProvenanceHelper.CreateReleaseSessionRequest(feedId, releaseId);
}
var buildId = tl.getVariable("Build.BuildId");
if (buildId != null) {
return ProvenanceHelper.CreateBuildSessionRequest(feedId, buildId);
}
throw new Error("Could not resolve Release.ReleaseId or Build.BuildId");
}
private static CreateReleaseSessionRequest(
feedId: string,
releaseId: string
): SessionRequest {
let releaseData = {
"System.CollectionId": tl.getVariable("System.CollectionId"),
"System.TeamProjectId": tl.getVariable("System.TeamProjectId"),
"Release.ReleaseId": releaseId,
"Release.ReleaseName": tl.getVariable("Release.ReleaseName"),
"Release.DefinitionName": tl.getVariable("Release.DefinitionName"),
"Release.DefinitionId": tl.getVariable("Release.DefinitionId")
};
var sessionRequest: SessionRequest = {
feed: feedId,
source: "InternalRelease",
data: releaseData
};
return sessionRequest;
}