Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (artifact.resource.type.toLowerCase() === "container") {
let downloader = new engine.ArtifactEngine();
var containerParts: string[] = artifact.resource.data.split('/', 3);
if (containerParts.length !== 3) {
throw new Error(tl.loc("FileContainerInvalidArtifactData"));
}
var containerId: number = parseInt(containerParts[1]);
var containerPath: string = containerParts[2];
var itemsUrl = endpointUrl + "/_apis/resources/Containers/" + containerId + "?itemPath=" + encodeURIComponent(containerPath) + "&isShallow=true&api-version=4.1-preview.4";
console.log(tl.loc("DownloadArtifacts", itemsUrl));
var variables = {};
var handler = new webHandlers.PersonalAccessTokenCredentialHandler(accessToken);
var webProvider = new providers.WebProvider(itemsUrl, templatePath, variables, handler);
var fileSystemProvider = new providers.FilesystemProvider(downloadPath);
downloadPromises.push(downloader.processItems(webProvider, fileSystemProvider, downloaderOptions).catch((reason) => {
reject(reason);
}));
}
else if (artifact.resource.type.toLowerCase() === "filepath") {
let downloader = new engine.ArtifactEngine();
let downloadUrl = artifact.resource.data;
let artifactLocation = downloadUrl + '/' + artifact.name;
if (!fs.existsSync(artifactLocation)) {
console.log(tl.loc("ArtifactNameDirectoryNotFound", artifactLocation, downloadUrl));
artifactLocation = downloadUrl;
}
console.log(tl.loc("DownloadArtifacts", artifactLocation));
return;
}
var itemsUrl = "https://api.github.com/repos/" + repositoryName + "/releases/" + release.Id + "/assets";
itemsUrl = itemsUrl.replace(/([^:]\/)\/+/g, "$1");
console.log(tl.loc("DownloadArtifacts", release.Name, itemsUrl));
var templatePath = path.join(__dirname, 'githubrelease.handlebars.txt');
var gitHubReleaseVariables = {
"endpoint": {
"url": "https://api.github.com/"
}
};
var webProvider = new providers.WebProvider(itemsUrl, templatePath, gitHubReleaseVariables, customCredentialHandler);
var fileSystemProvider = new providers.FilesystemProvider(downloadPath);
var parallelLimit: number = +tl.getVariable("release.artifact.download.parallellimit");
var downloader = new engine.ArtifactEngine();
var downloaderOptions = new engine.ArtifactEngineOptions();
downloaderOptions.itemPattern = itemPattern ? itemPattern : '**';
var debugMode = tl.getVariable('System.Debug');
downloaderOptions.verbose = debugMode ? debugMode.toLowerCase() != 'false' : false;
if (parallelLimit) {
downloaderOptions.parallelProcessingLimit = parallelLimit;
}
await downloader.processItems(webProvider, fileSystemProvider, downloaderOptions).then((result) => {
console.log(tl.loc('ArtifactsSuccessfullyDownloaded', downloadPath));
resolve();
async function getArtifactsFromUrl(artifactQueryUrl: string, strictSSL: boolean, localPathRoot: string, itemPattern: string, handler: handlers.BasicCredentialHandler, variables: { [key: string]: any }) {
console.log(tl.loc('ArtifactDownloadUrl', artifactQueryUrl));
var templatePath = path.join(__dirname, 'jenkins.handlebars.txt');
var webProvider = new providers.WebProvider(artifactQueryUrl, templatePath, variables, handler, { ignoreSslError: !strictSSL });
var localFileProvider = new providers.FilesystemProvider(localPathRoot);
var downloaderOptions = configureDownloaderOptions();
var downloader = new engine.ArtifactEngine();
await downloader.processItems(webProvider, localFileProvider, downloaderOptions);
}
let downloadPath = tl.getInput("downloadPath", true);
var endpointUrl = tl.getEndpointUrl(connection, false);
var itemsUrl = `${endpointUrl}/api/v1.1/project/${definitionId}/${buildId}/artifacts`;
itemsUrl = itemsUrl.replace(/([^:]\/)\/+/g, "$1");
console.log(tl.loc("DownloadArtifacts", itemsUrl));
var templatePath = path.join(__dirname, 'circleCI.handlebars.txt');
var username = tl.getEndpointAuthorizationParameter(connection, 'username', false);
var circleciVariables = {
"endpoint": {
"url": endpointUrl
}
};
var handler = new webHandlers.BasicCredentialHandler(username, "");
var webProvider = new providers.WebProvider(itemsUrl, templatePath, circleciVariables, handler);
var fileSystemProvider = new providers.FilesystemProvider(downloadPath);
var downloader = new engine.ArtifactEngine();
var downloaderOptions = new engine.ArtifactEngineOptions();
downloaderOptions.itemPattern = itemPattern ? itemPattern : '**';
var debugMode = tl.getVariable('System.Debug');
downloaderOptions.verbose = debugMode ? debugMode.toLowerCase() != 'false' : false;
var parallelLimit : number = +tl.getVariable("release.artifact.download.parallellimit");
if(parallelLimit){
downloaderOptions.parallelProcessingLimit = parallelLimit;
}
await downloader.processItems(webProvider, fileSystemProvider, downloaderOptions).then((result) => {
console.log(tl.loc('ArtifactsSuccessfullyDownloaded', downloadPath));
resolve();
var parallelLimit : number = +tl.getVariable("release.artifact.download.parallellimit");
if(parallelLimit){
downloaderOptions.parallelProcessingLimit = parallelLimit;
}
await downloader.processItems(webProvider, fileSystemProvider, downloaderOptions).then((result) => {
console.log(tl.loc('ArtifactsSuccessfullyDownloaded', downloadPath));
resolve();
}).catch((error) => {
reject(error);
});
let downloadCommitsFlag: boolean = tl.getBoolInput("downloadCommitsAndWorkItems", true);
if (downloadCommitsFlag) {
var webProviderForDownloaingCommits = new providers.WebProvider(itemsUrl, templatePath, circleciVariables, handler);
downloadCommits(webProviderForDownloaingCommits);
}
});
}
var containerId = parseInt(containerParts[1]);
var containerPath = containerParts.slice(2, containerParts.length).join('/');
if (containerPath == "/") {
//container REST api oddity. Passing '/' as itemPath downloads the first file instead of returning the meta data about the all the files in the root level.
//This happens only if the first item is a file.
containerPath = ""
}
var itemsUrl = endpointUrl + "/_apis/resources/Containers/" + containerId + "?itemPath=" + encodeURIComponent(containerPath) + "&isShallow=true&api-version=4.1-preview.4";
console.log(tl.loc("DownloadArtifacts", artifact.name, itemsUrl));
var variables = {};
var webProvider = new providers.WebProvider(itemsUrl, templatePath, variables, handler);
var fileSystemProvider = new providers.FilesystemProvider(downloadPath);
downloadPromises.push(downloader.processItems(webProvider, fileSystemProvider, downloaderOptions).catch((reason) => {
reject(reason);
}));
}
}
else if (artifact.resource.type.toLowerCase() === "filepath") {
let downloader = new engine.ArtifactEngine();
let downloadUrl = artifact.resource.data;
let artifactName = artifact.name.replace('/', '\\');
let artifactLocation = path.join(downloadUrl, artifactName);
if (!fs.existsSync(artifactLocation)) {
console.log(tl.loc("ArtifactNameDirectoryNotFound", artifactLocation, downloadUrl));
artifactLocation = downloadUrl;
}