Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support using 'Latest' as custom version #391

Open
wants to merge 25 commits into
base: dev
Choose a base branch
from
Open
Changes from 23 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions jfrog-tasks-utils/utils.js
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@ const jfrogCliReleasesUrl = 'https://releases.jfrog.io/artifactory/jfrog-cli/v2-
const pipelineRequestedCliVersionEnv = 'JFROG_CLI_PIPELINE_REQUESTED_VERSION_AZURE';
// The actual JFrog CLI version used in a task.
const taskSelectedCliVersionEnv = 'JFROG_CLI_TASK_SELECTED_VERSION_AZURE';
// Jfrog CLI version string to get latest version.
const jfrogCliReleaseVersionString = '[RELEASE]';

// Maven/Gradle Extractors Env:
const extractorsRemoteEnv = 'JFROG_CLI_EXTRACTORS_REMOTE';
@@ -97,6 +99,10 @@ function executeCliTask(runTaskFunc, cliVersion, cliDownloadUrl, cliAuthHandlers
// If CLI version is passed, use it. Otherwise, use requested version from env var if set. Else, default version.
cliVersion = tl.getVariable(pipelineRequestedCliVersionEnv) || defaultJfrogCliVersion;
}

// Convert 'latest' to '[RELEASE]' to get latest jfrog cli version
cliVersion = convertLatestVersionToReleaseIfNeeded(cliVersion)

// If unspecified, download from 'releases.jfrog.io' by default.
if (!cliDownloadUrl) {
cliDownloadUrl = buildReleasesDownloadUrl(cliVersion);
@@ -174,11 +180,11 @@ function generateDownloadCliErrorMessage(downloadUrl, cliVersion) {
let errMsg = 'Failed while attempting to download JFrog CLI from ' + downloadUrl + '. ';
if (downloadUrl === buildReleasesDownloadUrl(cliVersion)) {
errMsg +=
"If this build agent cannot access the internet, you may use the 'Artifactory Tools Installer' task, to download JFrog CLI through an Artifactory repository, which proxies " +
"\nIf this build agent cannot access the internet, you may use the 'Artifactory Tools Installer' task, to download JFrog CLI through an Artifactory repository, which proxies " +
buildReleasesDownloadUrl(cliVersion) +
'. You ';
'.\nYou ';
} else {
errMsg += 'If the chosen Artifactory Service cannot access the internet, you ';
errMsg += '\nIf the chosen Artifactory Service cannot access the internet, \nyou ';
}
errMsg += 'may also manually download version ' + cliVersion + ' of JFrog CLI and place it on the agent in the following path: ' + customCliPath;
return errMsg;
@@ -458,6 +464,11 @@ function addCommonGenericParams(cliCommand, specPath) {
function logCliVersionAndSetSelected(cliPath) {
try {
let detectedVersion = getCliVersion(cliPath);
// If the min version allowed is higher than the requested version we will fail the task.
if (compareVersions(minCustomCliVersion, detectedVersion) > 0) {
tl.setResult(tl.TaskResult.Failed, 'Custom JFrog CLI Version must be at least ' + minCustomCliVersion);
return;
}
console.log('JFrog CLI version: ' + detectedVersion);
tl.setVariable(taskSelectedCliVersionEnv, detectedVersion);
} catch (ex) {
@@ -496,6 +507,13 @@ function downloadCli(cliDownloadUrl, cliAuthHandlers, cliVersion = defaultJfrogC
toolLib
.downloadTool(cliDownloadUrl, null, cliAuthHandlers)
.then(downloadPath => {
// If cliVersion is not a semver ("[RELEASE]" for example), use the executable to get the downloaded version
if (!isSemverVersion(cliVersion)){
if (!isWindows()) {
fs.chmodSync(downloadPath, 0o555);
}
cliVersion = getCliVersion(downloadPath)
}
toolLib.cacheFile(downloadPath, fileName, jfrogCliToolName, cliVersion).then(cliDir => {
let cliPath = path.join(cliDir, fileName);
if (!isWindows()) {
@@ -511,6 +529,10 @@ function downloadCli(cliDownloadUrl, cliAuthHandlers, cliVersion = defaultJfrogC
});
}

function isSemverVersion(version) {
return version && version.split(".").length === 2
}

// Compares two versions.
// Returns 0 if the versions are equal, 1 if version1 is higher and -1 otherwise.
function compareVersions(version1, version2) {
@@ -804,3 +826,11 @@ function taskDefaultCleanup(cliPath, workDir, serverIdsArray) {
tl.setResult(tl.TaskResult.Failed, cleanupException);
}
}

// Convert latest to "[RELEASE]" to get latest jfrog cli version
function convertLatestVersionToReleaseIfNeeded(version) {
if (version && version.toLowerCase().localeCompare("latest") === 0){
return jfrogCliReleaseVersionString
}
return version
}
5 changes: 0 additions & 5 deletions tasks/JFrogCliV2/jfrogCliRun.js
Original file line number Diff line number Diff line change
@@ -18,11 +18,6 @@ function RunJfrogCliCommand(RunTaskCbk) {
}

let cliVersion = tl.getInput('cliVersion', true);
// If the min version allowed is higher than the requested version we will fail the task.
if (utils.compareVersions(utils.minCustomCliVersion, cliVersion) > 0) {
tl.setResult(tl.TaskResult.Failed, 'Custom JFrog CLI Version must be at least ' + utils.minCustomCliVersion);
return;
}
utils.executeCliTask(RunTaskCbk, cliVersion);
}

5 changes: 0 additions & 5 deletions tasks/JFrogToolsInstaller/toolsInstaller.js
Original file line number Diff line number Diff line change
@@ -12,11 +12,6 @@ function InstallCliAndExecuteCliTask(RunTaskCbk) {
// If the variable placeholder was passed (the variable was not set in the pipeline), use the default cli version.
if (tl.getBoolInput('installCustomVersion') && tl.getInput('cliVersion', true).localeCompare('$(jfrogCliVersion)') !== 0) {
cliVersion = tl.getInput('cliVersion', true);
// If the min version allowed is higher than the requested version we will fail the task.
if (utils.compareVersions(utils.minCustomCliVersion, cliVersion) > 0) {
tl.setResult(tl.TaskResult.Failed, 'Custom JFrog CLI Version must be at least ' + utils.minCustomCliVersion);
return;
}
}
// Set the requested CLI version env to download it now, and to use in succeeding tasks.
tl.setVariable(utils.pipelineRequestedCliVersionEnv, cliVersion);