相关文章推荐
发呆的茴香  ·  卢本伟好声音精选hhhhhh_哔哩哔哩_bi ...·  1 年前    · 
气势凌人的油条  ·  《我为歌狂》20年音乐梦想不变,上海美影厂经 ...·  1 年前    · 
耍酷的梨子  ·  夏县税务:“税惠味浓” 瓜香四溢·  1 年前    · 
老实的烈酒  ·  常见问答_中华人民共和国驻澳大利亚联邦大使馆·  2 年前    · 
儒雅的投影仪  ·  神偷奶爸:小黄人快跑_百度百科·  3 年前    · 
小百科  ›  JFrog Artifactory REST API in 5min | Ido Green
rest
八块腹肌的排球
3 年前

Subscribe

Subscribe and get the next post by Email

Yes! All the opinions expressed here are my own, and no other party necessarily agrees with them
Follow Ido Green on WordPress.com

Le Ha’aim!

always travel and do not forget to drink something (!) Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the BSD License.

Top Posts

  • JFrog Artifactory REST API in 5min
  • Discover the Best Gravel Routes Around the Bay Area: Uncover Scenic Paths and Adventure
  • Outlive: The Science and Art of Longevity - Book Review
  • Monitor Your Site With Apps Script
  • Export Violations From JFrog Xray to CSV

Categories

  • Android (8)
  • bots (32)
  • Business (160)
  • Chrome (222)
  • cloud (37)
  • Crypto (2)
  • Design (7)
  • good food (4)
  • hebrew (1)
  • HTML5 (123)
  • JavaScript (131)
  • life (142)
  • mobile (33)
  • php (11)
  • recipts (2)
  • Sport (35)
  • testing (3)
  • travel (7)
  • webdev (199)

    Most of the interactions with Artifactory will be from your CI/CD tools. It might be your build engine or from your log aggregator. This powerful API can be invoked in any of the standard ways you like to work with any other RESTful APIs (e.g. curl, CLI, your source code, etc’).
    In many cases, it’s the preferred ‘glue’ for developers when it comes to automation. The options are extensive and you can do many useful things with this API. However, in this short post, we will cover the most popular actions you ‘must have’.

    Let’s start with the most common action: “ upload/download binaries “. This action could run automatically from the build machine to Artifactory using:

    curl -u myUser:myP455w0rd! -X PUT "http://localhost:8081/artifactory/my-repository/my/new/artifact/directory/myAppBuild.exe" -T ./myAppBuild.exe And with the JFrog CLI: jfrog rt u ./myAppBuild.exe my-repository/my/new/artifact/directory/

    As for can see, you can work with the REST API from any technology you like. One good option is to use the JFrog CLI .
    It is a compact client (written in Go) that provides a simple interface to automate access to Artifactory. As a wrapper to the API, it offers a way to simplify automation scripts making them more readable and easier to maintain, features such as parallel uploads and downloads, checksum optimization and wildcards/regular expressions make your scripts more efficient and reliable.

    Downloading artifacts is one line of GET command:

    curl -u myUser:myP455w0rd! -X GET http://localhost:8081/artifactory/libs-release-local/ch/qos/logback/logback-classic/0.9.9/logback-classic-0.9.9.jar And with JFrog CLI: jfrog rt dl libs-release-local/ch/qos/logback/logback-classic/0.9.9/logback-classic-0.9.9.jar

    Search

    You will be astonished how quickly Artifactory will be the one source of true to all your binaries and how many of them you have. If you wish to find a certain package/library or build file – There is a powerful search API.
    You can do some quick searches like this one:

    curl -u myUser:myP455w0rd! http://localhost:8081/artifactory/api/search/artifact?name=lib&repos=libs-release-local OR with JFrog CLI: jfrog rt s libs-release-local/lib { "results": [ "uri": "http://localhost:8081/artifactory/api/storage/libs-release-local/org/acme/lib/ver/lib-ver.pom" "uri": "http://localhost:8081/artifactory/api/storage/libs-release-local/org/acme/lib/ver2/lib-ver2.pom"

    You can also search and find interesting data points like in the example below, we wish to query all the files that came out of the build (in this case, Jenkins) and that are bigger than 100Mb.

    // Put this: items.find( "type":"file", "created_by":"jenkins", "size":{"$gt":"100000"} .sort({"$desc":["size","name"]}) .limit(50) // Add the query to file: aql-query-1.txt so in the next command, You can execute it. // Search for the biggest files that our Jenkins built. // You can change it and tune the size/type of the files. // Let's use curl to get the results curl -uYourUserName:YourPassword -X POST http://ArtifactoryUrl/artifactory/api/search/aql -d @aql-query-1.txt -H \"content-type: text/plain\"";

    You will get a JSON response that will look like:

    "results" : [ { "repo" : "docker-prod-local", "path" : "docker-app/65", "name" : "sha256__a56a07bf8a7e40e8580e26b5c7ad51e88e130cce5537bd53aec960de3e9f4e3f", "type" : "file", "size" : 182286302, "created" : "2019-06-10T22:59:11.432Z", "created_by" : "jenkins", "modified" : "2019-06-10T22:59:08.982Z", "modified_by" : "jenkins", "updated" : "2019-06-10T22:59:11.433Z" "repo" : "docker-prod-local", "path" : "docker-framework/69", "name" : "sha256__a56a07bf8a7e40e8580e26b5c7ad51e88e130cce5537bd53aec960de3e9f4e3f", "type" : "file", "size" : 182286302, "created" : "2019-06-10T22:57:22.855Z", "created_by" : "jenkins", "modified" : "2019-06-10T22:57:19.454Z", "modified_by" : "jenkins", "updated" : "2019-06-10T22:57:22.856Z" "repo" : "docker-stage-local", "path" : "docker-app/65", "name" : "sha256__a56a07bf8a7e40e8580e26b5c7ad51e88e130cce5537bd53aec960de3e9f4e3f", "type" : "file", "size" : 182286302, "created" : "2019-06-10T22:59:11.432Z", "created_by" : "jenkins", "modified" : "2019-06-10T22:59:08.982Z", "modified_by" : "jenkins", "updated" : "2019-06-10T22:59:11.433Z" "range" : { "start_pos" : 0, "end_pos" : 3, "total" : 3, "limit" : 3

    Now, you can take this information and get even more data on each docker image or any other package, library, artifact you are using.

    Docker

    Docker is quite popular these days, so let’s get a list of all our Docker repositories:

    curl -u youUserName:youPassWord http://YouArtifactoryServer.com/artifactory/api/docker/docker-stage-local/v2/_catalog // The response: "repositories" : [ "docker-local-apps", "docker-prod-frameworks" ]

    Next, we can fetch the list of all the tags of specified Artifactory Docker repository:

    // GET /api/docker/{repo-key}/v2/{image name}/tags/list?n=<n from the request>&last=<last tag value from previous response> curl -u youUserName:youPassWord http://YouArtifactoryServer.com/artifactory/api/docker/docker-prod-local/v2/docker-app/tags/list // The response: "name" : "docker-app", "tags" : [ "59", "60", "61", "62", "63", "64", "65", "66", "67", "68" ]

    The full example

    This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
    Show hidden characters Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
    To find out more, including how to control cookies, see here: Cookie Policy
  •  
    推荐文章
    发呆的茴香  ·  卢本伟好声音精选hhhhhh_哔哩哔哩_bilibili
    1 年前
    气势凌人的油条  ·  《我为歌狂》20年音乐梦想不变,上海美影厂经典在B站“爷青回”
    1 年前
    耍酷的梨子  ·  夏县税务:“税惠味浓” 瓜香四溢
    1 年前
    老实的烈酒  ·  常见问答_中华人民共和国驻澳大利亚联邦大使馆
    2 年前
    儒雅的投影仪  ·  神偷奶爸:小黄人快跑_百度百科
    3 年前
    今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
    删除内容请联系邮箱 2879853325@qq.com
    小百科 - 百科知识指南
    © 2024 ~ 沪ICP备11025650号