{"id":58,"date":"2023-03-14T11:38:53","date_gmt":"2023-03-14T03:38:53","guid":{"rendered":"http:\/\/idc.birk.cn\/?p=58"},"modified":"2023-03-14T14:44:29","modified_gmt":"2023-03-14T06:44:29","slug":"gitlab-ci-cd%e5%85%b3%e9%94%ae%e8%af%8d%ef%bc%88%e4%b8%89%ef%bc%89%ef%bc%9a%e5%88%b6%e5%93%81artifacts%ef%bc%8c%e7%bc%93%e5%ad%98cache","status":"publish","type":"post","link":"https:\/\/idc.birk.cn\/?p=58","title":{"rendered":"GitLab CI\/CD\u5173\u952e\u8bcd\uff1a\u5236\u54c1artifacts"},"content":{"rendered":"<div class=\"article-title\">\n<h1><span style=\"font-size: 15px;\">\u672c\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecdGitLab CI\/CD\u5173\u952e\u8bcd\uff1a\u5236\u54c1artifacts\u4e3b\u8981\u5185\u5bb9\u5305\u62ec\u5176\u4f7f\u7528\u5b9e\u4f8b\u3001\u5e94\u7528\u6280\u5de7\u3001\u57fa\u672c\u77e5\u8bc6\u70b9\u603b\u7ed3\u548c\u9700\u8981\u6ce8\u610f\u4e8b\u9879\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002<\/span><\/h1>\n<\/div>\n<div id=\"code_example\" class=\"article-content\">\n<h1 id=\"\u7b80\u4ecb\">\u7b80\u4ecb<\/h1>\n<p>\u672c\u7bc7\u6587\u7ae0\u5c06\u8bb2\u89e3\u5236\u54c1artifacts\u5173\u952e\u8bcd\u3002\u8fd9\u4e2a\u5173\u952e\u8bcd\u90fd\u53ef\u4ee5\u5c06\u6d41\u6c34\u7ebf\u4e2d\u7684\u6587\u4ef6\u5b58\u50a8\u8d77\u6765\uff0c\u4f46\u533a\u522b\u70b9\u4e5f\u5f88\u591a\u3002<\/p>\n<h1 id=\"\u5236\u54c1artifacts\">\u5236\u54c1artifacts<\/h1>\n<p>\u4f7f\u7528artifacts\u5173\u952e\u8bcd\u53ef\u4ee5\u5c06\u5f53\u524d\u4f5c\u4e1a\u7684\u4e00\u4e9b\u6587\u4ef6\u5b58\u50a8\u8d77\u6765\uff0c\u53ef\u4ee5\u5b58\u50a8\u6587\u4ef6\u5939\u548c\u6587\u4ef6\u5217\u8868\u3002\u5e76\u4e14\u7528\u6237\u53ef\u4ee5\u9009\u62e9\u5728\u4f5c\u4e1a\u5931\u8d25\uff0c\u6210\u529f\u65f6\u6216\u8005\u603b\u662f\u5b58\u50a8\u6587\u4ef6\u3002\u4f7f\u7528artifacts\u50a8\u5b58\u7684\u6587\u4ef6\u5c06\u4f1a\u88ab\u4e0a\u4f20\u5230gitlab\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5728gitlab\u4e0a\u5728\u7ebf\u9884\u89c8\u4ed6\u4eec\u3002\u5b58\u50a8\u540e\u7684\u6587\u4ef6\u5c06\u4f1a\u5728\u4e0b\u4e00\u4e2a\u9636\u6bb5\u81ea\u52a8\u6062\u590d\u5230\u5f53\u524d\u7684\u5de5\u4f5c\u76ee\u5f55\u3002\u5f00\u53d1\u8005\u4e5f\u53ef\u4ee5\u81ea\u7531\u914d\u7f6e\u6062\u590d\u54ea\u4e9b\u5236\u54c1\uff0c\u4e0d\u6062\u590d\u54ea\u4e9b\u5236\u54c1\u3002\u88ab\u6062\u590d\u7684\u5236\u54c1\uff0c\u5b58\u653e\u7684\u4f4d\u7f6e\u4e0e\u4ee5\u524d\u4e00\u81f4\u3002<\/p>\n<p>\u4e0b\u9762\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50<\/p>\n<pre><code class=\"hljs bash\">MalzaharJob:\r\n  script: <span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">'The man who has made up his mind to win will never say \u201cimpossible\u201d.'<\/span>\r\n  artifacts:\r\n    paths:\r\n      - dist\/\r\n      - target\/\r\n<\/code><\/pre>\n<p>\u5728\u8be5\u4f8b\u5b50\u4e2d\uff0c\u5728\u4f5c\u4e1a\u4e0b\u4f7f\u7528artifacts\u6765\u5b58\u50a8\u4e00\u4e9b\u6587\u4ef6\u5939\uff0c\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u7684\u8def\u5f84\u90fd\u662f\u901a\u8fc7paths\u53c2\u6570\u6765\u6307\u5b9a\u7684\u3002\u9664\u4e86\u4f7f\u7528paths\u914d\u7f6e\u6587\u4ef6\u8def\u5f84\uff0c\u6587\u4ef6\u5939\u8def\u5f84\u5916\uff0c \u5728artifacts\u4e0b\uff0c\u6709\u4e0d\u5c11\u914d\u7f6e\u9879\uff0c\u4e0b\u9762\u4e3a\u5927\u5bb6\u9010\u4e2a\u4ecb\u7ecd\u3002<\/p>\n<h2 id=\"artifactsexclude-\u6392\u9664\u6587\u4ef6\">artifacts:exclude \u6392\u9664\u6587\u4ef6<\/h2>\n<p>\u4f7f\u7528exclude\u53c2\u6570\u53ef\u4ee5\u6392\u67e5\u4e00\u4e9b\u6587\u4ef6\u4e0d\u653e\u5230\u5236\u54c1\u4e2d\u3002\u5982<\/p>\n<pre><code class=\"hljs php\">MalzaharJob:\r\n  script: <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">'The man who has made up his mind to win will never say \u201cimpossible\u201d.'<\/span>\r\n  artifacts:\r\n    paths:\r\n      - dist\/\r\n      - target\/\r\n    exclude:\r\n      - target<span class=\"hljs-comment\">\/**\/<\/span>*.o\r\n<\/code><\/pre>\n<p>\u4f7f\u7528exclude\u6765\u6392\u67e5tagret\u76ee\u5f55\u4e0b\u7684\u4ee5\u00a0<code>.o<\/code>\u00a0\u7ed3\u5c3e\u7684\u6587\u4ef6\u3002 \u8fd9\u4e9b\u6587\u4ef6\u4e0d\u4f1a\u88ab\u4e0a\u4f20\u5230gitlab\u3002<\/p>\n<h2 id=\"artifactsexpire_in-\u8fc7\u671f\u65f6\u95f4\">artifacts:expire_in \u8fc7\u671f\u65f6\u95f4<\/h2>\n<p>\u4e0a\u4f20\u5230gitlab \u7684\u5236\u54c1\u53ef\u4ee5\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\uff0c\u8fc7\u671f\u540e\u5c06\u65e0\u6cd5\u83b7\u53d6\uff0c\u81ea\u52a8\u6e05\u7406\u3002<\/p>\n<p>\u5728gitlab\u4e2d\u5373\u4f7f\u8bbe\u7f6e\u4e86\u8fc7\u671f\u65f6\u95f4\uff0c\u6700\u65b0\u7684\u4f5c\u4e1a\u5236\u54c1\u4e5f\u4e0d\u4f1a\u88ab\u6e05\u7406\uff0c\u8fd9\u662f\u4e00\u79cd\u9632\u62a4\u624b\u6bb5\uff0c\u6b64\u5916\u8fd8\u6709\u6d41\u6c34\u7ebf\u5236\u54c1\uff0c\u8fd9\u91cc\u4e00\u822c\u7279\u6307\u6d4b\u8bd5\u62a5\u544a\u7b49\u3002<\/p>\n<p>expire_in\u7684\u503c\u652f\u6301\u7684\u6709\u5f88\u591a\uff0c\u4ee5\u4e0b\u51e0\u79cd\u683c\u5f0f\u90fd\u662f\u652f\u6301\u7684\u3002\u5982\u679c\u6ca1\u6709\u5355\u4f4d\uff0c\u9ed8\u8ba4\u7684\u5355\u4f4d\u4e3a\u79d2.<\/p>\n<pre><code class=\"hljs coffeescript\"><span class=\"hljs-string\">'42'<\/span>\r\n<span class=\"hljs-number\">42<\/span> seconds\r\n<span class=\"hljs-number\">3<\/span> mins <span class=\"hljs-number\">4<\/span> sec\r\n<span class=\"hljs-number\">2<\/span> hrs <span class=\"hljs-number\">20<\/span> min\r\n<span class=\"hljs-number\">2<\/span>h20min\r\n<span class=\"hljs-number\">6<\/span> mos <span class=\"hljs-number\">1<\/span> day\r\n<span class=\"hljs-number\">47<\/span> yrs <span class=\"hljs-number\">6<\/span> mos <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-number\">4<\/span>d\r\n<span class=\"hljs-number\">3<\/span> weeks <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-number\">2<\/span> days\r\nnever\r\n<\/code><\/pre>\n<p>\u5982\u679c\u6ca1\u6709\u8bbe\u7f6e\u4e00\u4e2a\u4f5c\u4e1a\u5236\u54c1\u7684\u8fc7\u671f\u65f6\u95f4\uff0c\u90a3\u4e48\u5c06\u9ed8\u8ba4\u4f7f\u7528 \u7ba1\u7406\u5458\u914d\u7f6e\u7684\u5236\u54c1\u5b58\u50a8\u65f6\u95f4\uff0c30\u5929\uff0c<a href=\"https:\/\/docs.gitlab.com\/ee\/user\/admin_area\/settings\/continuous_integration.html#default-artifacts-expiration\" target=\"_blank\" rel=\"noopener\">gitlab\u8d85\u7ba1\u53ef\u4ee5\u4fee\u6539\u5b83<\/a>\u3002 \u53c2\u8003\u7f51\u5740\uff1a<a href=\"https:\/\/www.cnblogs.com\/sanduzxcvbnm\/p\/15207203.html\" target=\"_blank\" rel=\"noopener\">https:\/\/www.cnblogs.com\/sanduzxcvbnm\/p\/15207203.html<\/a><\/p>\n<h2 id=\"artifactsexpose_as-\u5c55\u793a\u5728mr\u4e0a\u7684\u540d\u79f0\">artifacts:expose_as \u5c55\u793a\u5728MR\u4e0a\u7684\u540d\u79f0<\/h2>\n<p>\u4f7f\u7528expose_as\u53ef\u4ee5\u5b9a\u4e49\u5728\u5408\u5e76\u8bf7\u6c42\u65f6\u8981\u663e\u793a\u7684\u5236\u54c1\u540d\u79f0\u3002<\/p>\n<pre><code class=\"hljs bash\"><span class=\"hljs-built_in\">test<\/span>:\r\n  script: [<span class=\"hljs-string\">\"echo 'test' &gt; file.txt\"<\/span>]\r\n  artifacts:\r\n    expose_as: <span class=\"hljs-string\">'artifact 1'<\/span>\r\n    paths: [<span class=\"hljs-string\">'file.txt'<\/span>]\r\n<\/code><\/pre>\n<p>\u6ce8\u610f: artifacts:paths\u4e2d\u4f7f\u7528\u4e86CI\/CD\u53d8\u91cf\uff0c\u5236\u54c1\u5c06\u4e0d\u4f1a\u663e\u793a\u5728UI\u4e0a\u3002<\/p>\n<p>\u4e00\u4e2a\u5408\u5e76\u8bf7\u6c42\u6700\u591a\u53ea\u80fd\u66b4\u973210\u4e2a\u4f5c\u4e1a\u5236\u54c1, \u5168\u5c40\u6a21\u5f0f\u4e0b\u4e0d\u652f\u6301artifacts:expose_as, \u5982\u679c\u5f00\u542f\u4e86gitlab page\uff0c\u4e00\u4e9b\u7c7b\u578b\u7684\u5355\u4e2a\u6587\u4ef6\u53ef\u4ee5\u76f4\u63a5\u663e\u793a\u5728\u9875\u9762\u4e0a\u3002<\/p>\n<h2 id=\"artifactsname-\u5236\u54c1\u540d\u79f0\">artifacts:name \u5236\u54c1\u540d\u79f0<\/h2>\n<p>\u5f00\u53d1\u8005\u53ef\u4ee5\u6307\u5b9a\u5236\u54c1\u7684\u540d\u79f0\uff0c\u9ed8\u8ba4\u4e3aartifacts\u3002\u4e0b\u8f7d\u540e\u6587\u4ef6\u540d\u4e3a artifacts.zip\u3002\u53ef\u4ee5\u4f7f\u7528\u53d8\u91cf\u3002<\/p>\n<pre><code class=\"hljs bash\">build:\r\n  artifacts:\r\n    name: <span class=\"hljs-string\">\"<span class=\"hljs-variable\">$CI_JOB_NAME<\/span>-<span class=\"hljs-variable\">$CI_COMMIT_REF_NAME<\/span>\"<\/span>\r\n    paths:\r\n      - binaries\/\r\n<\/code><\/pre>\n<h2 id=\"artifactspaths-\u5236\u54c1\u6587\u4ef6\u8def\u5f84\">artifacts:paths \u5236\u54c1\u6587\u4ef6\u8def\u5f84<\/h2>\n<p>\u6307\u5b9a\u5236\u54c1\u4e2d\u6587\u4ef6\u7684\u8def\u5f84\u3002\u8def\u5f84\u5fc5\u987b\u662f\u5f53\u524d\u9879\u76ee\u8def\u5f84\u7684\u76f8\u5bf9\u8def\u5f84\uff0c\u4e0d\u80fd\u76f4\u63a5\u6307\u5b9a\u5916\u90e8\u8def\u5f84\u3002\u53ef\u4ee5\u4f7f\u7528\u901a\u914d\u7b26\u3002<\/p>\n<pre><code class=\"hljs bash\">build:\r\n  artifacts:\r\n    name: <span class=\"hljs-string\">\"<span class=\"hljs-variable\">$CI_JOB_NAME<\/span>-<span class=\"hljs-variable\">$CI_COMMIT_REF_NAME<\/span>\"<\/span>\r\n    paths:\r\n      - dist\/\r\n<\/code><\/pre>\n<h2 id=\"artifactspublic-\u662f\u5426\u516c\u5171\u53ef\u89c1\">artifacts:public \u662f\u5426\u516c\u5171\u53ef\u89c1<\/h2>\n<p>\u4f7f\u7528artifacts:public\u53ef\u4ee5\u914d\u7f6e\u5236\u54c1\u662f\u5426\u53ef\u4ee5\u88ab\u5916\u754c\u8bbf\u95ee\uff0c\u4e0b\u8f7d\u3002<\/p>\n<p>\u5728\u72ec\u81ea\u90e8\u7f72\u7684gitlab\u4e0a\uff0c\u8be5\u5c5e\u6027\u662f\u9ed8\u8ba4\u5173\u95ed\u7684\uff0c\u4f46\u8d85\u7ba1\u53ef\u4ee5\u5728\u7ba1\u7406\u9875\u9762\u5f00\u542f\u3002\u5728 gitlab.com\u4e0a\uff0c\u662f\u6ca1\u6709\u8be5\u5c5e\u6027\u7684\u3002<\/p>\n<p>\u5f53artifacts:public\u7684\u503c\u4e3atrue\u65f6\uff0c\u9ed8\u8ba4\u5c31\u662f\u4e3atrue\uff0c\u8fd9\u610f\u5473\u7740\u4f5c\u4e1a\u7684\u5236\u54c1\u53ef\u4ee5\u522b\u4efb\u4f55\u4eba\uff0c\u8bbf\u5ba2\u4e0b\u8f7d\u3002\u5982\u679c\u4e0d\u60f3\u88ab\u5176\u4ed6\u4eba\u770b\u5230\uff0c\u53ef\u4ee5\u662f\u8bbe\u7f6e\u4e3afalse<\/p>\n<pre><code class=\"hljs bash\">build:\r\n  artifacts:\r\n    name: <span class=\"hljs-string\">\"<span class=\"hljs-variable\">$CI_JOB_NAME<\/span>-<span class=\"hljs-variable\">$CI_COMMIT_REF_NAME<\/span>\"<\/span>\r\n    paths:\r\n      - dist\/\r\n    public: <span class=\"hljs-literal\">false<\/span>\r\n<\/code><\/pre>\n<h2 id=\"artifactsreports-\u6536\u96c6\u62a5\u544a\">artifacts:reports \u6536\u96c6\u62a5\u544a<\/h2>\n<p>artifacts:reports \u914d\u7f6e\u53ef\u4ee5\u6536\u96c6\u4e00\u4e9b\u4f7f\u7528include\u5173\u952e\u8bcd\u5f15\u5165\u7684\u6a21\u677f \u7684\u4f5c\u4e1a\u5236\u54c1\u3002\u5236\u54c1\u7c7b\u578b\u6709<a href=\"https:\/\/docs.gitlab.com\/ee\/ci\/yaml\/artifacts_reports.html\" target=\"_blank\" rel=\"noopener\">\u8fd9\u4e9b\u529f\u80fd<\/a>\u662f\u4ed8\u8d39\u7248\u672c\u624d\u6709\u7684\u3002<\/p>\n<h2 id=\"artifactsuntracked-\u4e0a\u4f20\u88abgit-\u5ffd\u7565\u7684\u6587\u4ef6\">artifacts:untracked \u4e0a\u4f20\u88abgit \u5ffd\u7565\u7684\u6587\u4ef6<\/h2>\n<p>\u4f7f\u7528artifacts:untracked\u53ef\u4ee5\u4e0a\u4f20\u4e00\u4e9b\u88abgit\u5ffd\u7565\u7684\u6587\u4ef6\u3002\u8fd9\u4e9b\u6587\u4ef6\u88ab\u6dfb\u52a0\u5230\u4e86<code>.gitignore<\/code>\u5217\u8868\u4e2d\u3002\u503c\u4e3a false\uff08\u9ed8\u8ba4\uff09\uff0c\u6216\u8005true\u3002<\/p>\n<pre><code class=\"hljs coffeescript\"><span class=\"hljs-attribute\">job<\/span>:\r\n  <span class=\"hljs-attribute\">artifacts<\/span>:\r\n    <span class=\"hljs-attribute\">untracked<\/span>: <span class=\"hljs-literal\">true<\/span>\r\n    <span class=\"hljs-attribute\">paths<\/span>:\r\n      - dist\/\r\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u4f1a\u5c06dist\u4e2d\u6240\u6709\u6587\u4ef6\u4e0a\u4f20\u5230\u5236\u54c1\u5e93\uff0c\u5373\u4f7fdist\u76ee\u5f55\u4e2d\u6709\u88abgit\u5ffd\u7565\u7684\u6587\u4ef6\u3002<\/p>\n<h2 id=\"artifactswhen-\u4f55\u65f6\u4e0a\u4f20\u5236\u54c1\">artifacts:when \u4f55\u65f6\u4e0a\u4f20\u5236\u54c1<\/h2>\n<p>artifacts:when \u7528\u4e8e\u914d\u7f6e\u5236\u54c1\u4e0a\u4f20\u7684\u65f6\u673a\uff0c\u6709\u4e09\u79cd\u9009\u62e9\uff0c<\/p>\n<ul>\n<li>on_success \u4f5c\u4e1a\u6210\u529f\u65f6\u4e0a\u4f20\uff0c\u9ed8\u8ba4\u3002<\/li>\n<li>on_failure \u4f5c\u4e1a\u8fd0\u884c\u5931\u8d25\u65f6\u4e0a\u4f20\uff0c<\/li>\n<li>always \u603b\u662f\u4e0a\u4f20\u3002\u53ef\u4ee5\u7528\u4e8e\u6536\u96c6\u4e00\u4e9b\u9519\u8bef\u65e5\u5fd7\u3002 \u5982\u679c\u4f5c\u4e1a\u8d85\u65f6\uff0c\u5219\u4e0d\u4f1a\u4e0a\u4f20\u3002<\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecdGitLab CI\/CD\u5173\u952e\u8bcd\uff1a\u5236\u54c1artifacts\u4e3b\u8981\u5185\u5bb9\u5305\u62ec\u5176\u4f7f\u7528\u5b9e\u4f8b\u3001\u5e94\u7528\u6280\u5de7\u3001\u57fa\u672c\u77e5\u8bc6\u70b9\u603b\u7ed3\u548c\u9700\u8981\u6ce8\u610f\u4e8b\u9879\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002 \u7b80\u4ecb \u672c\u7bc7\u6587\u7ae0\u5c06\u8bb2\u89e3\u5236\u54c1artifacts\u5173\u952e\u8bcd\u3002\u8fd9\u4e2a\u5173\u952e\u8bcd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[32,18,31],"topic":[30],"class_list":["post-58","post","type-post","status-publish","format-standard","hentry","category-21","tag-cicd","tag-devops","tag-gitlab","topic-devops"],"_links":{"self":[{"href":"https:\/\/idc.birk.cn\/index.php?rest_route=\/wp\/v2\/posts\/58","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.birk.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.birk.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.birk.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.birk.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=58"}],"version-history":[{"count":4,"href":"https:\/\/idc.birk.cn\/index.php?rest_route=\/wp\/v2\/posts\/58\/revisions"}],"predecessor-version":[{"id":76,"href":"https:\/\/idc.birk.cn\/index.php?rest_route=\/wp\/v2\/posts\/58\/revisions\/76"}],"wp:attachment":[{"href":"https:\/\/idc.birk.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.birk.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.birk.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=58"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/idc.birk.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}