Circle Ci 2.0 artifacts url
Asked Answered
L

2

9

Circle Ci 2.0 artifacts can be accessed with the following url

https://{BUILD_NUMBER}-{UNKNOWN_NUMBER}-gh.circle-artifacts.com/0

What does the number after CI build number represent.

Lankester answered 23/10, 2017 at 1:25 Comment(0)
C
8

If, like me, you were looking for a way to programmatically reference CircleCI (2.0) artifacts, the following url structure works for me:

https://circleci.com/api/v1.1/project/:vcs-type/:username/:project/:build_num/artifacts/0/:path-to-artifact?circle-token=:token&branch=:branch

For example:

https://circleci.com/api/v1.1/project/github/circleci/circleci-docs/latest/artifacts/0/run-results/build-results.txt?branch=realitycheck&filter=successful

resolves to the build-results.txt artifact on the latest, successful build of the circleci-docs project's realitycheck branch.

Constructing the :path-to-artifact can be done by inspecting your CircleCI artifacts directory structure:

enter image description here

From the above, the :path-to-artifact is 0/run-results/build-results.txt.

Reference:

Charland answered 17/10, 2018 at 9:53 Comment(4)
On the other hand, if you really just wanted to know what {UNKNOWN_NUMBER} is, I have no idea. ¯\_(ツ)_/¯Charland
There are also Bitbucket repos. So {UNKNOWN_NUMBER} dont't have to be a Github repo id as stated in answer below. Pretty sure CircleCI has an environment variable for it. And I would also like to know it :)Cymry
I ended up getting a permission error if I included the token so I used https://circleci.com/api/v1.1/project/:vcs-type/:username/:project/:build_num/artifacts/0/:path-to-artifact?circle-token=:token&branch=:branch and it worked beautifully!Dutyfree
The only that works for me is wget and a different URL. Also, i was mistaken in my understanding of what an artifacts is because after 30 days it is deleted!? So, how can I use it in my other builds then?!?Idiocy
D
2

The {UNKNOWN_NUMBER} represents the Github id of the repository.

If you run the snippet below you can get the id you want for any organisation and repository as provided by the github rest API

function query_gh(){
  var org = document.getElementById("org").value;
  var repo = document.getElementById("repo").value;

  async function query(org, repo) {
    const response = await fetch("https://api.github.com/orgs/"+org+"/repos");
    const outJson = await response.json();

    for (var i = 0; i < outJson.length; i++){
      var repository = outJson[i];
      if (repository.name == repo) {
        id = repository.id;
        output.innerHTML = org +"/"+ repo + " has ID: " + id;
        return true;
      }
    }
  }
  query(org, repo);
  return true;
}
<!DOCTYPE html>
<html>
<body>

<p>Enter names of the GH organisation and repository</p>
<form onsubmit="query_gh(); return false;">
 <label for="org">Organisation</label>
 <input type="text" id="org" required="">
 <br>
 <label for="repo">Repository</label>
 <input type="text" id="repo" required="">
 <br>
 <button type="submit">Query</button>

</form>

<div id="output">
 <span id="output_text">...</span>
</div>

</body>
</html>
Dislocation answered 5/1, 2019 at 21:5 Comment(2)
What in case of a Bitbucket repo?Cymry
With Bitbucket is the same but with the url as: https://{BUILD_NUMBER}-{BB-id}-bb.circle-artifacts.com/. You can print what's that URL with the ${CIRCLE_BUILD_URL} variable. To get that id for a BB repository go to: https://api.bitbucket.org/2.0/repositories/{username}/{repo_slug}/ and look for: uuid. Look at the bitbucket API for more details.Dislocation

© 2022 - 2024 — McMap. All rights reserved.