How to use the azure-pipelines-task-lib/task.setResult function in azure-pipelines-task-lib

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 jfrog / artifactory-vsts-extension / tasks / ArtifactoryGenericUpload / uploadArtifacts.js View on Github external
let cliCommand = utils.cliJoin(cliPath, cliUploadCommand, "--url=" + utils.quote(artifactoryUrl), "--spec=" + utils.quote(specPath));
    cliCommand = utils.addArtifactoryCredentials(cliCommand, artifactoryService);
    cliCommand = utils.addBoolParam(cliCommand, "failNoOp", "fail-no-op");

    // Add build info collection
    if (collectBuildInfo) {
        let buildName = tl.getInput('buildName', true);
        let buildNumber = tl.getInput('buildNumber', true);
        cliCommand = utils.cliJoin(cliCommand, "--build-name=" + utils.quote(buildName), "--build-number=" + utils.quote(buildNumber));
    }

    try {
        utils.executeCliCommand(cliCommand, workDir);
    } catch (executionException) {
        tl.setResult(tl.TaskResult.Failed, executionException);
    } finally {
        // Remove created fileSpec from file system.
        try {
            tl.rmRF(specPath);
        } catch (fileException) {
            tl.setResult(tl.TaskResult.Failed, "Failed cleaning temporary FileSpec file.");
        }
    }

    // Ignored if previously failed.
    tl.setResult(tl.TaskResult.Succeeded, "Build Succeeded.");
}
github jfrog / artifactory-vsts-extension / tasks / ArtifactoryGenericDownload / Ver2 / downloadArtifacts.js View on Github external
function performGenericDownload(cliPath, workDir, artifactoryService, artifactoryUrl) {
    let specPath = path.join(workDir, "downloadSpec" + Date.now() + ".json");

    // Get input parameters.
    let specSource = tl.getInput("specSource", false);
    let collectBuildInfo = tl.getBoolInput("collectBuildInfo");

    // Create download FileSpec.
    try {
        utils.writeSpecContentToSpecPath(specSource, specPath);
    } catch (ex) {
        tl.setResult(tl.TaskResult.Failed, ex);
        return;
    }

    // Build the cli command.
    let cliCommand = utils.cliJoin(cliPath, cliDownloadCommand, "--url=" + utils.quote(artifactoryUrl), "--spec=" + utils.quote(specPath));
    cliCommand = utils.addArtifactoryCredentials(cliCommand, artifactoryService);
    cliCommand = utils.addBoolParam(cliCommand, "failNoOp", "fail-no-op");
    // Add build info collection.
    if (collectBuildInfo) {
        let buildName = tl.getInput('buildName', true);
        let buildNumber = tl.getInput('buildNumber', true);
        cliCommand = utils.cliJoin(cliCommand, "--build-name=" + utils.quote(buildName), "--build-number=" + utils.quote(buildNumber));
    }

    // Execute the cli command.
    try {
github microsoft / azure-pipelines-tasks / Tasks / UsePythonV1 / main.ts View on Github external
task.setResourcePath(path.join(__dirname, 'task.json'));
        await usePythonVersion({
            version: task.getInput('version', false),
            architecture: task.getInput('architecture', true)
        },
        getPlatform());

        // Always set proxy.
        const proxy: tl.ProxyConfiguration | null = tl.getHttpProxyConfiguration();
        if (proxy) {
            proxyutil.setProxy(proxy);
        }

        task.setResult(task.TaskResult.Succeeded, "");
    } catch (error) {
        task.setResult(task.TaskResult.Failed, error.message);
    }
})();
github microsoft / google-play-vsts-extension / Tasks / google-play-rollout-update / google-play-rollout-update.ts View on Github external
const inProgressTrack = track.releases.find(x => x.status === 'inProgress');
        if (!inProgressTrack) {
            throw new Error(tl.loc('InProgressNotFound'));
        }

        console.log(tl.loc('CurrentUserFrac', inProgressTrack.userFraction));
        const updatedTrack: googleutil.Track = await googleutil.updateTrack(edits, packageName, rolloutTrack, inProgressTrack.versionCodes, userFraction, inProgressTrack.releaseNotes);
        tl.debug('Update Track: ' + JSON.stringify(updatedTrack));

        console.log(tl.loc('RolloutFracUpdate'));
        const commit = await edits.commit();
        tl.debug('Commit: ' + JSON.stringify(commit.data));

        tl.setResult(tl.TaskResult.Succeeded, tl.loc('Success'));
    } catch (err) {
        tl.setResult(tl.TaskResult.Failed, err);
    }
}
github geeklearningio / gl-vsts-tasks-yarn / Tasks / Yarn / yarnTask.ts View on Github external
if (overrideNpmrc) {
      tl.rmRF(projectNpmrc());
    }

    restoreProjectNpmrc(overrideNpmrc);

    tl.rmRF(npmrc);

    if (result) {
      tl.setResult(
        tl.TaskResult.Failed,
        `Yarn failed with exit code ${result}`
      );
    } else {
      tl.setResult(tl.TaskResult.Succeeded, "Yarn executed successfully");
    }
  } catch (err) {
    tl.debug(String(err));
    if (err.stack) {
      tl.debug(err.stack);
    }
    tl.setResult(tl.TaskResult.Failed, String(err));
  } finally {
    tl.rmRF(util.getTempPath());
  }
}
github jfrog / artifactory-vsts-extension / tasks / ArtifactoryConan / conanBuild.js View on Github external
function setTaskResult(taskSuccessful) {
    if (taskSuccessful) {
        tl.setResult(tl.TaskResult.Succeeded, "Conan Task finished.");
    } else {
        tl.setResult(tl.TaskResult.Failed, "Conan Task failed.");
    }
}
github microsoft / azure-pipelines-tasks / Tasks / DotNetCoreInstallerV1 / dotnetcoreinstaller.ts View on Github external
    .catch((error) => tl.setResult(tl.TaskResult.Failed, !!error.message ? error.message : error));
github microsoft / azure-pipelines-tasks / Tasks / UseDotNetV2 / Tests / versionInstallerDownloadAndInstallTests.ts View on Github external
}, (ex) => {
                    tl.setResult(tl.TaskResult.Failed, "ShouldNotHaveThrown");
                });
        }, (ex) => {
github microsoft / azure-pipelines-tasks / Tasks / NpmV1 / npm.ts View on Github external
main().catch(error => {
    tl.rmRF(util.getTempPath());
    tl.setResult(tl.TaskResult.Failed, error);
});