How to use the azure-pipelines-task-lib/task.exist 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 microsoft / azure-pipelines-tasks / Tasks / UseDotNetV2 / versioninstaller.ts View on Github external
private isLatestInstalledVersion(version: string): boolean {
        var pathTobeChecked = this.packageType == utils.Constants.sdk ? path.join(this.installationPath, utils.Constants.relativeSdkPath) : path.join(this.installationPath, utils.Constants.relativeRuntimePath);
        if (!tl.exist(pathTobeChecked)) {
            throw tl.loc("PathNotFoundException", pathTobeChecked);
        }

        var allEnteries: string[] = tl.ls("", [pathTobeChecked]).map(name => path.join(pathTobeChecked, name));
        var folderPaths: string[] = allEnteries.filter(element => fs.lstatSync(element).isDirectory());
        var isLatest: boolean = folderPaths.findIndex(folderPath => {
            try {
                let versionFolderName = path.basename(folderPath);
                tl.debug(tl.loc("ComparingInstalledFolderVersions", version, versionFolderName));
                return utils.versionCompareFunction(versionFolderName, version) > 0;
            }
            catch (ex) {
                // no op, folder name might not be in version format
            }
        }) < 0;
github microsoft / azure-pipelines-tasks / Tasks / DotNetCoreInstallerV1 / versioninstaller.ts View on Github external
public isVersionInstalled(version: string): boolean {
        if (!toolLib.isExplicitVersion(version)) {
            throw tl.loc("ExplicitVersionRequired", version);
        }

        var isInstalled: boolean = false;
        if (this.packageType == utils.Constants.sdk) {
            isInstalled = tl.exist(path.join(this.installationPath, utils.Constants.relativeSdkPath, version)) && tl.exist(path.join(this.installationPath, utils.Constants.relativeSdkPath, `${version}.complete`));
        }
        else {
            isInstalled = tl.exist(path.join(this.installationPath, utils.Constants.relativeRuntimePath, version)) && tl.exist(path.join(this.installationPath, utils.Constants.relativeRuntimePath, `${version}.complete`));
        }

        isInstalled ? console.log(tl.loc("VersionFoundInCache", version)) : console.log(tl.loc("VersionNotFoundInCache", version));
        return isInstalled;
    }
github microsoft / azure-pipelines-tasks / Tasks / UseDotNetV2 / versioninstaller.ts View on Github external
public isVersionInstalled(version: string): boolean {
        if (!toolLib.isExplicitVersion(version)) {
            throw tl.loc("ExplicitVersionRequired", version);
        }

        var isInstalled: boolean = false;
        if (this.packageType == utils.Constants.sdk) {
            isInstalled = tl.exist(path.join(this.installationPath, utils.Constants.relativeSdkPath, version)) && tl.exist(path.join(this.installationPath, utils.Constants.relativeSdkPath, `${version}.complete`));
        }
        else {
            isInstalled = tl.exist(path.join(this.installationPath, utils.Constants.relativeRuntimePath, version)) && tl.exist(path.join(this.installationPath, utils.Constants.relativeRuntimePath, `${version}.complete`));
        }

        isInstalled ? console.log(tl.loc("VersionFoundInCache", version)) : console.log(tl.loc("VersionNotFoundInCache", version));
        return isInstalled;
    }
github microsoft / azure-pipelines-tasks / Tasks / TwineAuthenticateV0 / authcleanup.ts View on Github external
async function run() {
    tl.setResourcePath(path.join(__dirname, "task.json"));
    const pypircPath = tl.getVariable("PYPIRC_PATH");
    if (tl.exist(pypircPath)) {
        tl.debug(tl.loc("Info_RemovingPypircFile", pypircPath));
        tl.rmRF(pypircPath);
    }
    else {
        console.log(tl.loc("NoPypircFile"));
    }
}
run();
github aws / aws-vsts-tools / Tasks / CloudFormationCreateOrUpdateStack / TaskOperations.ts View on Github external
private loadParametersFromFile(parametersFile: string): CloudFormation.Parameters | undefined {
        if (!parametersFile) {
            console.log(tl.loc('NoParametersFileSpecified'))

            return undefined
        }

        console.log(tl.loc('LoadingTemplateParametersFile', parametersFile))
        if (!tl.exist(parametersFile)) {
            throw new Error(tl.loc('ParametersFileDoesNotExist', parametersFile))
        }

        const parameterContent = fs.readFileSync(parametersFile, 'utf8')
        const templateParameters = this.parseParameters(parameterContent)

        return templateParameters
    }
github microsoft / azure-pipelines-tasks / Tasks / AndroidSigningV3 / postandroidsigning.ts View on Github external
async function run() {
    try {
        tl.setResourcePath(path.join(__dirname, 'task.json'));
        const keystoreFile: string = tl.getTaskVariable('KEYSTORE_FILE_PATH');
        if (keystoreFile && tl.exist(keystoreFile)) {
            fs.unlinkSync(keystoreFile);
            tl.debug('Deleted keystore file downloaded from the server: ' + keystoreFile);
        }
    } catch (err) {
        tl.warning(tl.loc('DeleteKeystoreFileFailed', err));
    }
}
github microsoft / azure-pipelines-tasks / Tasks / DownloadPackageV0 / download.ts View on Github external
await new Promise(function (resolve, reject) {
		if (tl.exist(unzipLocation)) {
			tl.rmRF(unzipLocation);
		}

		tl.debug('Extracting ' + zipLocation + ' to ' + unzipLocation);

		var unzipper = new DecompressZip(zipLocation);
		unzipper.on('error', err => {
			return reject(tl.loc("ExtractionFailed", err))
		});
		unzipper.on('extract', log => {
			tl.debug('Extracted ' + zipLocation + ' to ' + unzipLocation + ' successfully');
			return resolve();
		});

		unzipper.extract({
			path: unzipLocation
github microsoft / azure-pipelines-tasks / Tasks / VsTestV2 / helpers.ts View on Github external
public static pathExistsAsFile(path: string) {
        return tl.exist(path) && tl.stats(path).isFile();
    }
github geeklearningio / gl-vsts-tasks-yarn / Tasks / YarnInstaller / util.ts View on Github external
export function getTempPath(): string {
  let tempNpmrcDir =
    tl.getVariable("Agent.BuildDirectory") ||
    tl.getVariable("Agent.ReleaseDirectory") ||
    process.cwd();
  let tempPath = path.join(tempNpmrcDir, "yarn");
  if (tl.exist(tempPath) === false) {
    tl.mkdirP(tempPath);
  }

  return tempPath;
}