How to use azure-pipelines-task-lib - 10 common examples

To help you get started, we’ve selected a few azure-pipelines-task-lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jfrog / artifactory-vsts-extension / tasks / ArtifactoryNuget / nugetBuild.js View on Github external
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;
github microsoft / azure-pipelines-tasks / Tasks / PublishTestResultsV2 / Tests / L0.ts View on Github external
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";
github microsoft / azure-pipelines-tasks / Tasks / DotNetCoreInstallerV1 / versioninstaller.ts View on Github external
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);
        }
    }
github jfrog / artifactory-vsts-extension / tasks / ArtifactoryConan / conanBuild.js View on Github external
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;
    }
github jfrog / artifactory-vsts-extension / tasks / ArtifactoryToolsInstaller / toolsInstaller.js View on Github external
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;
    }
github microsoft / google-play-vsts-extension / Tasks / google-play-release-bundle / GooglePlay.ts View on Github external
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
github microsoft / code-push-vsts-extension / Tasks / codepush-release-cordova / codepush-release-cordova.js View on Github external
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.
github microsoft / code-push-vsts-extension / Tasks / codepush-patch / codepush-patch.js View on Github external
// 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)
github microsoft / code-push-vsts-extension / Tasks / codepush-patch / codepush-patch.js View on Github external
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), 
        {
github microsoft / code-push-vsts-extension / Tasks / codepush-promote / codepush-promote.js View on Github external
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,