Use a generic CI with Conan and Artifactory

Warning

Some problems regarding the use of BuildInfo with Conan packages have been reported. If the BuildInfo contains artifacts that have the same checksum as other artifacts, this may result in losing the path of the artifact in the BuildInfo in Artifactory and also fail in the promotion process.

We are currently working along with the Artifactory team to solve those problems. Until this issue gets fixed, we do not recommend using BuildInfo’s for Conan.

Uploading the BuildInfo

If you are using Jenkins with Conan and Artifactory, along with the Jenkins Artifactory Plugin, any Conan package downloaded or uploaded during your build will be automatically recorded in the BuildInfo json file, that will be automatically uploaded to the specified Artifactory instance.

However, using the conan_build_info command, you can gather and upload that information using other CI infrastructure. There are two possible ways of using this command:

Extracting build-info from the Conan trace log

  1. Before calling Conan the first time in your build, set the environment variable CONAN_TRACE_FILE to a file path. The generated file will contain the BuildInfo json.

  2. You also need to create the artifacts.properties file in your Conan home containing the build information. All this properties will be automatically associated to all the published artifacts.

artifact_property_build.name=MyBuild
artifact_property_build.number=23
artifact_property_build.timestamp=1487676992
  1. Call Conan as many times as you need. For example, if you are testing a Conan package and uploading it at the end, you will run something similar to:

$ conan create . user/stable # Will retrieve the dependencies and create the package
$ conan upload mypackage/1.0@user/stable -r artifactory
  1. Call the command conan_build_info passing the path to the generated Conan traces file and a parameter --output to indicate the output file. You can also, delete the traces.log` file` otherwise while the CONAN_TRACE_FILE is present, any Conan command will keep appending actions.

$ conan_build_info /tmp/traces.log --output /tmp/build_info.json
$ rm /tmp/traces.log
  1. Edit the build_info.json file to append name (build name), number (build number) and the started (started date) and any other field that you need according to the Build Info json format.

    The started field has to be in the format: yyyy-MM-dd'T'HH:mm:ss.SSSZ

    To edit the file you can import the json file using the programming language you are using in your framework, groovy, java, python…

  2. Push the json file to Artifactory, using the REST-API:

curl -X PUT -u<username>:<password> -H "Content-type: application/json" -T /tmp/build_info.json "http://host:8081/artifactory/api/build"

Generating build info from lockfiles information

Warning

This is an experimental feature subject to breaking changes in future releases.

To maintain compatibility with the current implementation of the conan_build_info command, this version must be invoked using the argument --v2 before any subcommand.

1. To begin associating the build information to the uploaded packages the first thing is calling to the start subcommand of conan_build_info. This will set the artifact_property_build.name and artifact_property_build.name properties in the artifacts.properties.

$ conan_build_info --v2 start MyBuildName 42

2. Call Conan using lockfiles to create information for the Build Info json format.

$ cd mypackage
$ conan create . mypackage/1.0@user/stable # We create one package
$ cd .. && cd consumer
$ conan install . # Consumes mypackage, generates a lockfile
$ conan create . consumer/1.0@user/stable --lockfile conan.lock
$ conan upload "*" -c -r local # Upload all packages to local remotes

3. Create build information based on the contents of the generated conan.lock lockfile and the information retrieved from the remote (the authentication is for the remote where you uploaded the packages).

$ conan_build_info --v2 create buildinfo.json --lockfile conan.lock --user admin --password password
  1. Publish the build information to Artifactory with the publish subcommand:

Using user and password

$ conan_build_info --v2 publish buildinfo.json --url http://localhost:8081/artifactory --user admin --password password

or an API key:

$ conan_build_info --v2 publish buildinfo.json --url http://localhost:8081/artifactory --apikey apikey

5. If the whole process has finished and you don’t want to continue associating the build number and build name to the files uploaded to Artifactory then you can use the stop subcommand:

$ conan_build_info --v2 stop

It is also possible to merge different build info files using the update subcommand. This is useful in CI when many slaves are generating different build info files.

$ conan_build_info --v2 update buildinfo1.json buildinfo2.json --output-file mergedbuildinfo.json

You can check the complete conan_build_info reference.