Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'azure-pipelines-task-lib' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
let nugetExec = tl.which("nuget", false);
if (!nugetExec && nugetCommand.localeCompare("restore") === 0) {
let localVersions = toolLib.findLocalToolVersions(NUGET_TOOL_NAME);
if (localVersions === undefined || localVersions.length === 0) {
await(downloadAndRunNuget(cliPath, nugetCommand));
} else {
console.log("The following version/s " + localVersions + " were found on the build agent");
addToPathAndExec(cliPath, nugetCommand, localVersions[localVersions.length - 1]);
}
} else {
exec(cliPath, nugetCommand);
}
});
if (process.platform !== "win32") {
tl.setResult(tl.TaskResult.Failed, "This task currently supports Windows agents only.");
return;
}
utils.executeCliTask(RunTaskCbk);
// Executing JFrog CLI with NuGet
function exec(cliPath, nugetCommand) {
let buildDir = tl.getVariable('System.DefaultWorkingDirectory');
// Get configured parameters
let nugetCommandCli;
if (nugetCommand.localeCompare("restore") === 0) {
// Perform restore command.
let solutionPattern = tl.getInput("solutionPath");
let filesList = solutionPathUtil.resolveFilterSpec(solutionPattern, tl.getVariable("System.DefaultWorkingDirectory") || process.cwd());
filesList.forEach(solutionFile => {
let solutionPath;
it('Command should not be called when exe returns with exit code for feature flag on', (done: MochaDone) => {
console.log('TestCaseName: Command should not be called when exe returns with exit code for feature flag on');
// Setup the mock runner
const tp = path.join(__dirname, 'TestSetup.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
// Set the inputs
process.env[constants.osType] = 'Windows_NT';
process.env[constants.testRunner] = 'VSTest';
process.env[constants.testResultsFiles] = '"n-files0.xml"';
process.env[constants.mergeTestResults] = 'false';
process.env[constants.failTaskOnFailedTests] = 'false';
process.env[constants.platform] = '';
process.env[constants.configuration] = '';
process.env[constants.testRunTitle] = '';
process.env[constants.publishRunAttachments] = 'false';
process.env[constants.searchFolder] = '';
process.env[constants.listPackagesReturnCode] = '0';
process.env[constants.agentTempDirectory] = __dirname;
process.env[constants.proxyUrl] = "http://example.org";
process.env[constants.proxyUserName] = "1";
directoriesTobeCopied.forEach((directoryPath) => {
tl.cp(directoryPath, this.installationPath, "-rf", false);
});
// Copy files
try {
if (this.packageType == utils.Constants.sdk && this.isLatestInstalledVersion(version)) {
tl.debug(tl.loc("CopyingFilesIntoPath", this.installationPath));
var filesToBeCopied = allRootLevelEnteriesInDir.filter(path => !fs.lstatSync(path).isDirectory());
filesToBeCopied.forEach((filePath) => {
tl.cp(filePath, this.installationPath, "-f", false);
});
}
}
catch (ex) {
tl.warning(tl.loc("FailedToCopyTopLevelFiles", this.installationPath, ex));
}
// Cache tool
this.createInstallationCompleteFile(versionInfo);
console.log(tl.loc("SuccessfullyInstalled", this.packageType, version));
}
catch (ex) {
throw tl.loc("FailedWhileInstallingVersionAtPath", version, this.installationPath, ex);
}
}
let handleAddRemoteCommand = async(function () {
let remoteName = tl.getInput("remoteName", true);
let artifactoryService = tl.getInput("artifactoryService", true);
let artifactoryUrl = tl.getEndpointUrl(artifactoryService, false);
let artifactoryUser = tl.getEndpointAuthorizationParameter(artifactoryService, "username", true);
let artifactoryPassword = tl.getEndpointAuthorizationParameter(artifactoryService, "password", true);
let artifactoryAccessToken = tl.getEndpointAuthorizationParameter(artifactoryService, "apitoken", true);
let conanRepo = tl.getInput("conanRepo", true);
let purgeExistingRemotes = tl.getBoolInput("purgeExistingRemotes", true);
if (artifactoryAccessToken) {
// Access token is not supported.
console.error("Access Token is not supported for authentication with Artifactory, please configure Artifactory service connection" +
" to work with basic authentication.");
setTaskResult(false);
return;
}
function RunTaskCbk(cliPath) {
let installMavenExtractor = tl.getBoolInput("installMavenExtractor");
if (!installMavenExtractor) {
tl.setResult(tl.TaskResult.Succeeded, "Tools installed successfully.");
return;
}
console.log("Installing Maven Extractor...");
// Get inputs and variables
let artifactoryService = tl.getInput("artifactoryService");
let buildName = tl.getVariable('Build.DefinitionName');
let buildNumber = tl.getVariable('Build.BuildNumber');
let workDir = tl.getVariable('System.DefaultWorkingDirectory');
if (!workDir) {
tl.setResult(tl.TaskResult.Failed, "Failed getting default working directory.");
return;
}
console.log(tl.loc('FoundMainBundle', bundleFile));
tl.debug(`Found the main bundle file: ${bundleFile}.`);
const versionCodeFilterType: string = tl.getInput('versionCodeFilterType', false) || 'all';
let versionCodeFilter: string | string[] = null;
if (versionCodeFilterType === 'list') {
versionCodeFilter = getVersionCodeListInput();
} else if (versionCodeFilterType === 'expression') {
versionCodeFilter = tl.getInput('replaceExpression', true);
}
const track: string = tl.getInput('track', true);
const userFractionSupplied: boolean = tl.getBoolInput('rolloutToUserFraction');
const userFraction: number = Number(userFractionSupplied ? tl.getInput('userFraction', false) : 1.0);
const shouldAttachMetadata: boolean = tl.getBoolInput('shouldAttachMetadata', false);
let changelogFile: string = null;
let languageCode: string = null;
let metadataRootPath: string = null;
if (shouldAttachMetadata) {
metadataRootPath = tl.getPathInput('metadataRootPath', true, true);
} else {
changelogFile = tl.getInput('changelogFile', false);
languageCode = tl.getInput('languageCode', false) || 'en-US';
}
const globalParams: googleutil.GlobalParams = { auth: null, params: {} };
let bundleVersionCode: number;
// The submission process is composed
tl.debug("Working directories do not match: ");
tl.debug("cwd: " + process.cwd());
tl.debug("expected cwd: " + cwd);
tl.debug("task will likely fail");
}
// If function arguments are provided (e.g. during test), use those, else, get user inputs provided by VSTS.
var authType = tl.getInput("authType", false);
if (authType === "AccessKey") {
accessKey = tl.getInput("accessKey", true);
} else if (authType === "ServiceEndpointCodePush" || authType === "ServiceEndpointHockeyApp") {
var serviceAccount = tl.getEndpointAuthorization(tl.getInput(authType, true));
accessKey = serviceAccount.parameters.password;
}
appName = appName || tl.getInput("appName", true);
deploymentName = deploymentName || tl.getInput("deploymentName", false);
platform = platform || tl.getInput("platform", true);
shouldBuild = shouldBuild || tl.getBoolInput("shouldBuild", false);
appStoreVersion = appStoreVersion || tl.getInput("appStoreVersion", false);
rollout = rollout || tl.getInput("rollout", false);
description = description || tl.getInput("description", false);
isMandatory = isMandatory || tl.getBoolInput("isMandatory", false);
isDisabled = isDisabled || tl.getBoolInput("isDisabled", false);
if (!accessKey) {
console.error("Access key required");
tl.setResult(1, "Access key required");
}
// Ensure all other users are logged out.
// If function arguments are provided (e.g. during test), use those, else, get user inputs provided by VSTS.
var authType = tl.getInput("authType", false);
if (authType === "AccessKey") {
accessKey = tl.getInput("accessKey", true);
} else if (authType === "ServiceEndpointCodePush" || authType === "ServiceEndpointHockeyApp") {
var serviceAccount = tl.getEndpointAuthorization(tl.getInput(authType, true));
accessKey = serviceAccount.parameters.password;
}
appName = appName || tl.getInput("appName", true);
deploymentName = deploymentName || tl.getInput("deploymentName", true);
label = label || tl.getInput("releaseLabel", false);
description = description || tl.getInput("description", false);
isDisabled = isDisabled || tl.getInput("isDisabled", false);
isMandatory = isMandatory || tl.getInput("isMandatory", false);
rollout = rollout || tl.getInput("rollout", false);
appStoreVersion = appStoreVersion || tl.getInput("appStoreVersion", true);
if (!accessKey) {
console.error("Access key required");
tl.setResult(1, "Access key required");
}
var codePushSdk = new CodePushSdk(accessKey);
codePushSdk.patchRelease(
appName, deploymentName, (label === "latest" ? null : label),
{
description: (description === "noChange" ? null : description),
disabled: (isDisabled === "noChange" ? null : isDisabled),
mandatory: (isMandatory === "noChange" ? null : isMandatory),
rollout: (rollout === "noChange" ? null : parseInt(rollout.replace("%", ""))),
targetBinaryVersion: (appStoreVersion === "noChange" ? null : appStoreVersion)
function performPatchTask(accessKey, appName, deploymentName, label, description, isDisabled, isMandatory, rollout, appStoreVersion) {
// If function arguments are provided (e.g. during test), use those, else, get user inputs provided by VSTS.
var authType = tl.getInput("authType", false);
if (authType === "AccessKey") {
accessKey = tl.getInput("accessKey", true);
} else if (authType === "ServiceEndpointCodePush" || authType === "ServiceEndpointHockeyApp") {
var serviceAccount = tl.getEndpointAuthorization(tl.getInput(authType, true));
accessKey = serviceAccount.parameters.password;
}
appName = appName || tl.getInput("appName", true);
deploymentName = deploymentName || tl.getInput("deploymentName", true);
label = label || tl.getInput("releaseLabel", false);
description = description || tl.getInput("description", false);
isDisabled = isDisabled || tl.getInput("isDisabled", false);
isMandatory = isMandatory || tl.getInput("isMandatory", false);
rollout = rollout || tl.getInput("rollout", false);
appStoreVersion = appStoreVersion || tl.getInput("appStoreVersion", true);
if (!accessKey) {
console.error("Access key required");
tl.setResult(1, "Access key required");
}
var codePushSdk = new CodePushSdk(accessKey);
codePushSdk.patchRelease(
appName, deploymentName, (label === "latest" ? null : label),
{
function performPromoteTask(accessKey, appName, sourceDeploymentName, targetDeploymentName, appStoreVersion, description, rollout, isMandatory, isDisabled) {
// If function arguments are provided (e.g. during test), use those, else, get user inputs provided by VSTS.
var authType = tl.getInput("authType", false);
if (authType === "AccessKey") {
accessKey = tl.getInput("accessKey", true);
} else if (authType === "ServiceEndpointCodePush" || authType === "ServiceEndpointHockeyApp") {
var serviceAccount = tl.getEndpointAuthorization(tl.getInput(authType, true));
accessKey = serviceAccount.parameters.password;
}
appName = appName || tl.getInput("appName", true);
sourceDeploymentName = sourceDeploymentName || tl.getInput("sourceDeploymentName", true);
targetDeploymentName = targetDeploymentName || tl.getInput("targetDeploymentName", true);
appStoreVersion = appStoreVersion || tl.getInput("appStoreVersion", false);
description = description || tl.getInput("description", false);
rollout = rollout || tl.getInput("rollout", false);
isMandatory = isMandatory || tl.getInput("isMandatory", true);
isDisabled = isDisabled || tl.getInput("isDisabled", true);
if (!accessKey) {
console.error("Access key required");
tl.setResult(1, "Access key required");
}
var updateMetadata = {
targetBinaryVersion: appStoreVersion === "Inherit" ? null : appStoreVersion,
description: description === "Inherit" ? null : description,