manbetx客户端打不开CI获得最后的神器 [英] GitLab CI get last artifact

查看:73
本文介绍了manbetx客户端打不开CI获得最后的神器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 curl 获得最新的构建工件.这是我尝试过的.

I'm trying to get the latest build artifact using curl. Here's what I've tried.

首先,获取最后一个管道ID:

First, get last pipeline id:

curl -v -H "Content-Type: application/json" -H "PRIVATE-TOKEN: <my-token-here>" https://<project>/api/v4/projects/<project>/pipelines?per_page=1&page=1

接下来,根据之前获得的管道ID获取作业ID:

Next, get job id based on pipeline id just obtained before:

curl -sS --header "PRIVATE-TOKEN: <my-token-here>" "https://[redacted,host]/api/v4/projects/[redacted,project]/pipelines/<pipeline-id>/jobs" | jq '.[] | select(.name == "build-assets" and .status == "success" and .artifacts_file != null) | .id'

最后,根据作业ID将工件获取到 build.zip :

Finally, get the artifacts to build.zip based on job id:

curl -sS --header "PRIVATE-TOKEN: <my-token-here>" "https://[redacted,host]/api/v4/projects/[redacted, project]/jobs/<JOB_ID>/artifacts" > build.zip

上面的这些步骤确实有效,但是我必须击中三个端点(并为每个步骤处理JSON响应).

These steps above do work, but I have to hit three endpoints (and process the JSON response for each step).

我还阅读了 GitLab文档,为此有一个单个端点.所以我也尝试了这个:

I also read in GitLab's documentation, that there's a single endpoint available for this. So I also tried this:

curl -sS --header "PRIVATE-TOKEN: <my-token-here>" "https://<url>/<namespace>/<project>/-/jobs/artifacts/<refs>/download?job=<job_name>"

但这总是将我重定向到登录页面,说:

but this always redirects me to the login page, saying this:

<html><body>You are being <a href="https://<url>/users/sign_in">redirected</a>.</body></html>

有没有更简单的方法来执行此任务?还是适当地使用上面文档中描述的端点?

Is there any simpler way to do this task? Or how to use the endpoint that is described on the documentation above propeprly?

推荐答案

脚本脚本下载

两种方法.第二个是您用例中的解决方案.

Scripting artifacts download

Two methods. The second one is the solution in your use case.

curl -sS "https://<url>/<namespace>/<project>/-/jobs/artifacts/<refs>/download?job=<job_name>"

注意:很抱歉,您不能在此处使用您的个人令牌,它已保留给以下API使用.

Note : I gess you can't use your personal token here, it's reserved to API usage bellow.

Gitlab文档:下载最新的工件

curl -L --header "PRIVATE-TOKEN: 123456abcdef" "https://gitlab.com/api/v4/projects/awesome-organization%2Fawesome-group%2Fowesome-project/jobs/artifacts/master/download?job=publish-release"

Note1: -l <​​/code>告诉curl遵循重定向,因为gitlab会将您移动到其Google存储位置.
注意2:如果您的项目是gitlab的一部分或组或子组,则%2F 值是反斜杠的url编码替换.

Note1 : the -l tells curl to follow the redirection since gitlab will move you to its google storage location.
Note2 : the %2F value is the url-encoded replacement for the slash if your project is part or a group or subgroup in gitlab.

Gitlab api文档:下载最新的工件a>

这篇关于manbetx客户端打不开CI获得最后的神器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆