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

conan2 support #434

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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
91 changes: 60 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,60 @@ The *[JFrog Extension](https://marketplace.visualstudio.com/items?itemName=JFrog

## Table of contents

- [Table of contents](#Table-of-contents)
- [Overview](#Overview)
- [Download and Installation](#Download-and-Installation)
- [Installing the Extension](#Installing-the-Extension)
- [Installing the Build Agent](#Installing-the-Build-Agent)
- [Configuring the Service Connections](#Configuring-the-Service-Connections)
- [Executing JFrog CLI Commands](#Executing-JFrog-CLI-Commands)
- [Build tools Tasks](#build-tools-tasks)
- [JFrog Maven](#JFrog-Maven-Task)
- [JFrog Gradle](#JFrog-Gradle-Task)
- [JFrog Npm](#JFrog-Npm-Task)
- [JFrog Nuget](#JFrog-Nuget-and-NET-Core-Task)
- [JFrog .NET Core](#JFrog-Nuget-and-NET-Core-Task)
- [JFrog Pip](#JFrog-Pip-Task)
- [JFrog Conan](#JFrog-Conan-Task)
- [JFrog Go](#JFrog-Go-Task)
- [Build Tasks](#Build-tasks)
- [JFrog Collect Build Issues](#JFrog-Collect-Build-Issues)
- [JFrog Publish Build Info](#JFrog-Publish-Build-Info)
- [JFrog Build Promotion](#JFrog-Build-Promotion)
- [Discarding Published Builds](#Discarding-Published-Builds-from-Artifactory)
- [Managing Generic Artifacts](#Managing-Generic-Artifacts)
- [JFrog Xray](#JFrog-Xray-tasks)
- [Audit project's dependencies for Security Vulnerabilities](#Audit-projects-dependencies-for-Security-Vulnerabilities)
- [Scanning Published Builds for Security Vulnerabilities with JFrog Xray](#Scanning-Published-Builds-for-Security-Vulnerabilities)
- [JFrog Docker Tasks](#JFrog-Docker-tasks)
- [Pushing and Pulling Docker Images to and from Artifactory](#Pushing-and-Pulling-Docker-Images-to-and-from-Artifactory)
- [Scanning Local Docker Images with JFrog Xray](#Scanning-Local-Docker-Images-with-JFrog-Xray)
- [JFrog Distribution](#Managing-and-Distributing-Release-Bundles)
- [JFrog Distribution Task](#JFrog-Distribution-V2-Task)
- [Contributions](#Contribution)
- [JFrog Azure DevOps Extension](#jfrog-azure-devops-extension)
- [Overview](#overview)
- [Table of contents](#table-of-contents)
- [Download and Installation](#download-and-installation)
- [Installing the Extension](#installing-the-extension)
- [Installing the Build Agent](#installing-the-build-agent)
- [Automatic Installation](#automatic-installation)
- [Custom tools Installation](#custom-tools-installation)
- [Manual Installation](#manual-installation)
- [Installing JFrog CLI](#installing-jfrog-cli)
- [Installing the Maven Extractor](#installing-the-maven-extractor)
- [Installing the Gradle Extractor](#installing-the-gradle-extractor)
- [Installing Conan](#installing-conan)
- [Using TFS 2015](#using-tfs-2015)
- [Configuring the Service Connections](#configuring-the-service-connections)
- [Executing JFrog CLI Commands](#executing-jfrog-cli-commands)
- [JFrog CLI V2 Task](#jfrog-cli-v2-task)
- [Managing Generic Artifacts](#managing-generic-artifacts)
- [Generic artifacts handling](#generic-artifacts-handling)
- [Downloading generic build dependencies from Artifactory](#downloading-generic-build-dependencies-from-artifactory)
- [Uploading generic build artifacts to Artifactory](#uploading-generic-build-artifacts-to-artifactory)
- [Setting / Deleting properties on files in Artifactory](#setting--deleting-properties-on-files-in-artifactory)
- [Moving / Copying / Deleting artifacts in Artifactory](#moving--copying--deleting-artifacts-in-artifactory)
- [Build tools Tasks](#build-tools-tasks)
- [JFrog Maven Task](#jfrog-maven-task)
- [JFrog Gradle Task](#jfrog-gradle-task)
- [JFrog Npm Task](#jfrog-npm-task)
- [JFrog Nuget and .NET Core Task](#jfrog-nuget-and-net-core-task)
- [JFrog Pip Task](#jfrog-pip-task)
- [JFrog Conan Task](#jfrog-conan-task)
- [JFrog Go Task](#jfrog-go-task)
- [Build Tasks](#build-tasks)
- [JFrog Collect Build Issues](#jfrog-collect-build-issues)
- [Configuration properties](#configuration-properties)
- [JFrog Publish Build Info](#jfrog-publish-build-info)
- [JFrog Build Promotion](#jfrog-build-promotion)
- [Using Build Promotion in a Release](#using-build-promotion-in-a-release)
- [Discarding Published Builds from Artifactory](#discarding-published-builds-from-artifactory)
- [JFrog Xray tasks](#jfrog-xray-tasks)
- [Audit project's dependencies for Security Vulnerabilities](#audit-projects-dependencies-for-security-vulnerabilities)
- [Scanning Published Builds for Security Vulnerabilities](#scanning-published-builds-for-security-vulnerabilities)
- [JFrog Docker tasks](#jfrog-docker-tasks)
- [Pushing and Pulling Docker Images to and from Artifactory](#pushing-and-pulling-docker-images-to-and-from-artifactory)
- [Scanning Local Docker Images with JFrog Xray](#scanning-local-docker-images-with-jfrog-xray)
- [Using Published Artifacts in a Release](#using-published-artifacts-in-a-release)
- [Using JFrog Generic Artifacts task](#using-jfrog-generic-artifacts-task)
- [Using Azure Artifact source](#using-azure-artifact-source)
- [Managing and Distributing Release Bundles](#managing-and-distributing-release-bundles)
- [JFrog Distribution V2 Task](#jfrog-distribution-v2-task)
- [Contribution](#contribution)
- [Building](#building)
- [Testing](#testing)
- [Skipping Tests](#skipping-tests)
- [Reporting issues](#reporting-issues)

## Download and Installation

Expand Down Expand Up @@ -661,6 +684,12 @@ The full documentation of Conan is available at the [conan website](https://docs
pathOrReference: './'
buildName: '$(Build.DefinitionName)'
buildNumber: '$(Build.BuildNumber)'
- task: JFrogConanV2@2
inputs:
conanCommand: 'Install'
pathOrReference: './'
buildName: '$(Build.DefinitionName)'
buildNumber: '$(Build.BuildNumber)'
```

For more information about Conan repositories,
Expand Down
246 changes: 246 additions & 0 deletions tasks/JFrogConanV2/conanBuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
const conanutils = require('./conanUtils.js');
const tl = require('azure-pipelines-task-lib/task');
const utils = require('@jfrog/tasks-utils/utils.js');

function run() {
let conanCommand = tl.getInput('conanCommand', true);

// Handle different conan commands
switch (conanCommand) {
case 'Config Install':
handleConfigInstallCommand();
break;
case 'Add Remote':
handleAddRemoteCommand();
break;
case 'Create':
handleCreateCommand();
break;
case 'Install':
handleInstallCommand();
break;
case 'Upload':
handleUploadCommand();
break;
case 'Custom':
handleCustomCommand();
break;
default:
tl.setResult(tl.TaskResult.Failed, 'Conan Command not supported: ' + conanCommand);
}
}

/**
* Handle Conan Config Install Command
*/
function handleConfigInstallCommand() {
let configSourceType = tl.getInput('configSourceType', true);
let configInstallItem = tl.getInput('configInstallItem', true);
let extraArguments = tl.getInput('extraArguments', false);

let conanArguments = ['config', 'install'];
conanArguments = addExtraArguments(conanArguments, extraArguments);
conanArguments.push('--type');
conanArguments.push(configSourceType);
conanArguments.push(configInstallItem);

conanutils
.executeConanTask(conanArguments)
.then(() => {
setTaskResult(true);
})
.catch((err) => {
console.error('Failed to execute Conan Task: ' + err.message);
setTaskResult(false);
});
}

/**
* Handle Conan Add Remote Command
*/
function handleAddRemoteCommand() {
let remoteName = tl.getInput('remoteName', true);
let artifactoryService = tl.getInput('artifactoryConnection', 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;
}

let conanArguments = [
'remote',
'add',
remoteName,
utils.stripTrailingSlash(artifactoryUrl) + '/api/conan/' + conanRepo,
'--index',
'0',
'--force',
];

// Purge existing
if (purgeExistingRemotes) {
try {
conanutils.purgeConanRemotes();
} catch (err) {
console.error('Failed to purge Conan Remotes: ' + err.message);
setTaskResult(false);
return;
}
}

// Add remote repo configuration
conanutils
.executeConanTask(conanArguments)
.then(() => {
// Add user credentials
conanArguments = ['remote', 'login', '--password', artifactoryPassword, remoteName, artifactoryUser];
conanutils.executeConanTask(conanArguments).then(() => {
setTaskResult(true);
});
})
.catch((err) => {
console.error('Failed to execute Conan Task: ' + err.message);
setTaskResult(false);
});
}

/**
* Handle Conan Create Command
*/
function handleCreateCommand() {
let createPath = tl.getPathInput('createPath', true, true);
let extraArguments = tl.getInput('extraArguments', false);

let conanArguments = ['create'];
conanArguments = addExtraArguments(conanArguments, extraArguments);
conanArguments.push(createPath);

conanutils
.executeConanTask(conanArguments)
.then(() => {
setTaskResult(true);
})
.catch((err) => {
console.error('Failed to execute Conan Task: ' + err.message);
setTaskResult(false);
});
}

/**
* Handle Conan Install Command
*/
function handleInstallCommand() {
let pathOrReference = tl.getInput('pathOrReference', true);
let extraArguments = tl.getInput('extraArguments', false);

let conanArguments = ['install'];
conanArguments = addExtraArguments(conanArguments, extraArguments);
conanArguments.push(pathOrReference);

conanutils
.executeConanTask(conanArguments)
.then(() => {
setTaskResult(true);
})
.catch((err) => {
console.error('Failed to execute Conan Task: ' + err.message);
setTaskResult(false);
});
}

/**
* Handle Conan Upload Command
*/
function handleUploadCommand() {
let patternOrReference = tl.getInput('patternOrReference', true);
let extraArguments = tl.getInput('extraArguments', false);

let conanArguments = ['upload'];
conanArguments = addExtraArguments(conanArguments, extraArguments);
// Enforce --confirm option since the command runs in a non-interactive mode
enforceArgumentOrOption(conanArguments, '-c', '--confirm');
conanArguments.push(patternOrReference);

conanutils
.executeConanTask(conanArguments)
.then(() => {
setTaskResult(true);
})
.catch((err) => {
console.error('Failed to execute Conan Task: ' + err.message);
setTaskResult(false);
});
}

/**
* Handle Conan Custom Command
*/
function handleCustomCommand() {
let customArguments = tl.getInput('customArguments', true);
let conanArguments = customArguments.split(' ');

conanutils
.executeConanTask(conanArguments)
.then(() => {
setTaskResult(true);
})
.catch((err) => {
console.error('Failed to execute Conan Task: ' + err.message);
setTaskResult(false);
});
}

/**
* Add extra arguments to list of options and arguments
*
* @param conanArguments (Array) - Collection of options and arguments
* @param extraArguments (String) - String containing the input of extra options and arguments
*/
function addExtraArguments(conanArguments, extraArguments) {
if (extraArguments && extraArguments.trim().length > 0) {
let extraArgumentsArray = extraArguments.split(' ');
return conanArguments.concat(extraArgumentsArray);
}
return conanArguments;
}

/**
* Enforce the presence of an option or argument in the list of arguments
*
* @param conanArguments (Array) - Collection of options and arguments
* @param shortVersion (string) - Short version of option or argument
* @param longVersion (string) - Long version of option or argument
*/
function enforceArgumentOrOption(conanArguments, shortVersion, longVersion) {
if (conanArguments.indexOf(shortVersion) < 0 && conanArguments.indexOf(longVersion) < 0) {
conanArguments.push(longVersion);
}
}

/**
* Set Task Result
*
* @param taskSuccessful (Boolean) - Flag with task result.
* True: Task was Successful.
* False: Task failed.
*/
function setTaskResult(taskSuccessful) {
if (taskSuccessful) {
tl.setResult(tl.TaskResult.Succeeded, 'Conan Task finished.');
} else {
tl.setResult(tl.TaskResult.Failed, 'Conan Task failed.');
}
}

run();
6 changes: 6 additions & 0 deletions tasks/JFrogConanV2/conanUtils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// conanUtils.d.ts
// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace conan_utils {
function getCliPartialsBuildDir(buildName: string, buildNumber: string): string;
}
export = conan_utils;
Loading
Loading