Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions tasks/JFrogCliV2/jfrogCliRun.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const tl = require('azure-pipelines-task-lib/task');
const utils = require('@jfrog/tasks-utils/utils.js');
const fs = require('fs');
const path = require('path');

let serverId;
RunJfrogCliCommand(RunTaskCbk);
Expand Down Expand Up @@ -49,6 +50,10 @@ async function RunTaskCbk(cliPath) {
serverId = utils.assembleUniqueServerId('jfrog_cli_cmd');
await utils.configureDefaultJfrogServer(serverId, cliPath, requiredWorkDir);

if (tl.getBoolInput('registerInPath')) {
tl.prependPath(path.dirname(cliPath));
}

let cliCommandsList = tl.getInput('command', true).split('\n');
try {
for (let cliCommand of cliCommandsList) {
Expand Down
8 changes: 8 additions & 0 deletions tasks/JFrogCliV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
"defaultValue": "",
"required": false,
"helpMarkDown": "The working directory where the command will run. When empty, the value of '$(System.DefaultWorkingDirectory)' is used."
},
{
"name": "registerInPath",
"type": "boolean",
"label": "Add JFrog CLI to PATH",
"defaultValue": "false",
"required": false,
"helpMarkDown": "Add the JFrog CLI executable's directory to the agent's PATH, so subsequent steps in the pipeline job can call 'jf' directly."
}
],
"execution": {
Expand Down
9 changes: 9 additions & 0 deletions tests/resources/jfrogCliV2RegisterInPath/registerInPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const testUtils = require('../../testUtils');

let inputs = {
jfrogPlatformConnection: 'mock-service',
registerInPath: true,
command: 'jf rt ping',
};

testUtils.runPlatformTask(testUtils.genericCli, {}, inputs);
27 changes: 27 additions & 0 deletions tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,20 @@ describe('JFrog Artifactory Extension Tests', (): void => {
);
});

describe('JFrog CLI V2 Tests', (): void => {
runSyncTest(
'Adds the JFrog CLI directory to PATH when registerInPath is enabled',
async (): Promise<void> => {
const runner: adoMockTest.MockTestRunner = await mockTaskCapture('jfrogCliV2RegisterInPath', 'registerInPath');
assert.ok(
/##vso\[task\.prependpath\].+/.test(runner.stdout),
'Expected a "prependpath" logging command in task output.\n' + runner.stdout,
);
},
TestUtils.isSkipTest('generic'),
);
});

describe('Tools Installer Tests', (): void => {
runSyncTest(
'Download CLI',
Expand Down Expand Up @@ -1420,13 +1434,26 @@ function runAsyncTest(description: string, testFunc: (done: mocha.Done) => void,
* @param shouldFail (Boolean, Optional) - True if the task supposed to fail
*/
async function mockTask(testDir: string, taskName: string, shouldFail?: boolean): Promise<void> {
await mockTaskCapture(testDir, taskName, shouldFail);
}

/**
* Mock a task from resources directory, returning the runner so its stdout/stderr can be inspected
* (e.g. to assert on a "##vso[...]" logging command, or to pull a value out of the task's output).
*
* @param testDir (String) - The test directory in resources
* @param taskName (String) - The '.js' file
* @param shouldFail (Boolean, Optional) - True if the task supposed to fail
*/
async function mockTaskCapture(testDir: string, taskName: string, shouldFail?: boolean): Promise<adoMockTest.MockTestRunner> {
const taskPath: string = join(__dirname, 'resources', testDir, taskName + '.js');
// task.json dummy passed to the mock runner to avoid the 'Unable to find task.json, ...' warnings.
const taskJsonDummy: string = join(__dirname, 'resources', 'task.json');
const mockRunner: adoMockTest.MockTestRunner = new adoMockTest.MockTestRunner(taskPath, taskJsonDummy);
await mockRunner.runAsync();
tasksOutput += mockRunner.stderr + '\n' + mockRunner.stdout;
assert.ok(shouldFail ? mockRunner.failed : mockRunner.succeeded, '\nFailure in: ' + taskPath + '.\n' + tasksOutput); // Check the test results
return mockRunner;
}

/**
Expand Down
Loading