問題描述
將構建目錄 (/dist) 從一個作業傳遞到大廳中的下一個作業 (Pass build directory (/dist) from a job to next job in concourse)
我知道這樣做並不簡單,並嘗試探索許多方法,但要么我無法正確理解它,要么不適合我。
我有一個運行角度的大廳工作build (ng build) 並創建 /dist 文件夾。這很好用。
jobs:
‑ name: cache
plan:
‑ get: source
trigger: true
‑ get: npm‑cache
‑ name: build
plan:
‑ get: source
trigger: true
passed: [cache]
‑ get: npm‑cache
passed: [cache]
‑ task: run build
file: source/ci/build.yml
build.yml
‑‑‑
platform: linux
image_resource:
type: docker‑image
source: { repository: alexsuch/angular‑cli, tag: '7.3' }
inputs:
‑ name: source
‑ name: npm‑cache
path: /cache
outputs:
‑ name: artifact
run:
path: source/ci/build.sh
build.sh
#!/bin/sh
mv cache/node_modules source
cd source
npm rebuild node‑saas # temporary fix
npm run build_prod
cp ‑R dist ../artifact/
我已經提到輸出是我存儲 dist 內容的工件。但是當我試圖在下一份工作中使用它時,它不起作用。由於缺少輸入錯誤而失敗。
這是應該使用此 dist 文件夾的下一個作業:
jobs:
...
...
‑ name: list
plan:
‑ get: npm‑cache
passed: [cache, test, build]
trigger: true
‑ task: list‑files
config:
platform: linux
image_resource:
type: registry‑image
source: { repository: busybox }
inputs:
‑ name: artifact
run:
path: ls
args: ['‑la', 'artifact/']
誰能幫我解決這個問題。我如何在上述工作中使用 dist 文件夾。
參考解法
方法 1:
I'm not quite sure why would you want to have different plan definitions for each task but here is the simplest way of doing what you want to do:
jobs:
‑ name: deploying‑my‑app
plan:
‑ get: source
trigger: true
passed: []
‑ get: npm‑cache
passed: []
‑ task: run build
file: source/ci/build.yml
‑ task: list‑files
file: source/ci/list‑files.yml
build.yml
‑‑‑
platform: linux
image_resource:
type: docker‑image
source: { repository: alexsuch/angular‑cli, tag: '7.3' }
inputs:
‑ name: source
‑ name: npm‑cache
path: /cache
outputs:
‑ name: artifact
run:
path: source/ci/build.sh
list‑files.yml
‑‑‑
platform: linux
image_resource:
type: registry‑image
source: { repository: busybox }
inputs:
‑ name: artifact
run:
path: ls
args: ['‑la', 'artifact/']
build.sh
#!/bin/sh
mv cache/node_modules source
cd source
npm rebuild node‑saas # temporary fix
npm run build_prod
cp ‑R dist ../artifact/
Typically you would pass folders as inputs and outputs between TASKS instead of JOBS (althought there's some alternatives)
Concourse is statelessness and that is the idea behind it. But if you want to pass something between jobs the only way to do that is to use a concourse resource and depending on the nature of the project that could be anything from a git repo to a s3 bucket, docker image etc. You can create your own custom resources too.
Using something like s3 concourse resource for example
This way you can push your artifact to an external storage and then use it again on the next jobs on the get step as a resource. But that just may create some unnecesary complexity understanding that what you want to do is pretty straightforward
In my experience I found that sometimes the visual aspect of a job plan in the concourse dashboard gives the impression that a job‑plan should by task atomic, which is not always needed
Hope that helps.
(by undefined、Peter Arboleda)