首页 > 解决方案 > Gitlab:无法使用 URL 下载工件

问题描述

我正在尝试使用 URL 方法下载工件。在GitLab,我收到以下错误:

117$ https://gitlab.myserver.com/mynamespace/jt/-/jobs/artifacts/master/download?job=job_make_patch
118/bin/bash: line 100: https://gitlab.myserver.com/mynamespace/jt/-/jobs/artifacts/master/download?job=job_make_patch: No such file or directory

代码:

job_make:
  tags:
    - test123
  image: node:10.19
  stage: build
  script:
    - npm install
    - make
    - make source-package
  cache:
    key: ${CI_COMMIT_REF_SLUG}
    paths:
    - node_modules/
  artifacts:
    when:
    paths:
      - test.tar.bz2
    expire_in: 2 days

job_test_patch:
  tags:
    - test123
  stage: deploy
  image: mycustomerdockerimage
  script:
    -  https://gitlab.myserver.com/mynamespace/jt/-/jobs/artifacts/master/download?job=job_make
    - ls -lah

我的项目是内部的,每个有权访问的人都可以看到它。我也确保在项目设置中检查“公共管道”。

当我手动尝试 curl 调用时,这就是我得到的:

PS C:\Users\jj\> curl -v https://gitlab.myserver.com/mynamespace/jt/-/jobs/artifacts/master/download?job=job_make
VERBOSE: GET https://gitlab.myserver.com/mynamespace/jt/-/jobs/artifacts/master/download?job=job_make with 0-byte payload
VERBOSE: received -1-byte response of content type text/html; charset=utf-8


PS C:\Users\jj\> curl -v https://gitlab.myserver.com/mynamespace/jt/-/jobs/artifacts/master/download?job=job_make
VERBOSE: GET https://gitlab.myserver.com/mynamespace/jt/-/jobs/artifacts/master/download?job=job_make with 0-byte payload
VERBOSE: received -1-byte response of content type text/html; charset=utf-8


StatusCode        : 200
StatusDescription : OK
Content           : <!DOCTYPE html>
                    <html class="devise-layout-html">
                    <head prefix="og: http://ogp.me/ns#">
                    <meta charset="utf-8">
                    <meta content="IE=edge" http-equiv="X-UA-Compatible">

                    <meta content="object" property="o...
RawContent        : HTTP/1.1 200 OK
                    Transfer-Encoding: chunked
                    Connection: keep-alive
                    Vary: Accept-Encoding
                    Referrer-Policy: strict-origin-when-cross-origin,strict-origin-when-cross-origin
                    X-Content-Type-Options: no...
Forms             : {new_user}
Headers           : {[Transfer-Encoding, chunked], [Connection, keep-alive], [Vary, Accept-Encoding], [Referrer-Policy, strict-origin-when-cross-origin,strict-origin-when-cross-origin]...}
Images            : {}
InputFields       : {@{innerHTML=; innerText=; outerHTML=<input name="utf8" type="hidden" value="✓&quot;>; outerText=; tagName=INPUT; name=utf8; type=hidden; value=✓}, @{innerHTML=; innerText=;
                    outerHTML=<input name="authenticity_token" type="hidden" value="OncopKrJ1jOr+BsMQdWIPNaJjoWvkAia6rHR6hUexNoyHJiBUfMVPm+ww0HqAn7h9oRtRqVdcoLgSxZYotJsxg==">; outerText=; tagName=INPUT;
                    name=authenticity_token; type=hidden; value=OncopKrJ1jOr+BsMQdWIPNaJjoWvkAia6rHR6hUexNoyHJiBUfMVPm+ww0HqAn7h9oRtRqVdcoLgSxZYotJsxg==}, @{innerHTML=; innerText=; outerHTML=<input
                    name="user[login]" title="This field is required." class="form-control top" id="user_login" autofocus="autofocus" required="required" type="text" data-qa-selector="login_field"
                    autocorrect="off" autocapitalize="off">; outerText=; tagName=INPUT; name=user[login]; title=This field is required.; class=form-control top; id=user_login; autofocus=autofocus;
                    required=required; type=text; data-qa-selector=login_field; autocorrect=off; autocapitalize=off}, @{innerHTML=; innerText=; outerHTML=<input name="user[password]" title="This field is
                    required." class="form-control bottom" id="user_password" required="required" type="password" data-qa-selector="password_field">; outerText=; tagName=INPUT; name=user[password];
                    title=This field is required.; class=form-control bottom; id=user_password; required=required; type=password; data-qa-selector=password_field}...}
Links             : {@{innerHTML=Sign in; innerText=Sign in; outerHTML=<a class="nav-link active" role="tab" href="#login-pane" data-qa-selector="sign_in_tab" data-toggle="tab">Sign in</a>;
                    outerText=Sign in; tagName=A; class=nav-link active; role=tab; href=#login-pane; data-qa-selector=sign_in_tab; data-toggle=tab}, @{innerHTML=Forgot your password?; innerText=Forgot
                    your password?; outerHTML=<a href="/users/password/new">Forgot your password?</a>; outerText=Forgot your password?; tagName=A; href=/users/password/new}, @{innerHTML=Explore;
                    innerText=Explore; outerHTML=<a href="/explore">Explore</a>; outerText=Explore; tagName=A; href=/explore}, @{innerHTML=Help; innerText=Help; outerHTML=<a href="/help">Help</a>;
                    outerText=Help; tagName=A; href=/help}...}
ParsedHtml        : System.__ComObject
RawContentLength  : 9914

我想要获取的工件存储库中基本上有一个 zip 文件。谢谢。

标签: gitlabgitlab-ci

解决方案


问题中显示的脚本似乎缺少curl部分:

script:
    -  curl -kL https://....
       ^^^^^^^^

文档提到

下载整个工件存档的 URL 结构如下:

https://example.com/<namespace>/<project>/-/jobs/artifacts/<ref>/download?job=<job_name>

因此,只要您在所述脚本中使用 curl,您的 URL 应该可以工作。


推荐阅读