將構建目錄 (/dist) 從一個作業傳遞到大廳中的下一個作業 (Pass build directory (/dist) from a job to next job in concourse)


問題描述

將構建目錄 (/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 undefinedPeter Arboleda)

參考文件

  1. Pass build directory (/dist) from a job to next job in concourse (CC BY‑SA 2.5/3.0/4.0)

#concourse #concourse-pipeline






相關問題

進行飛行同步時的未知目標 (unknown target when doing a fly sync)

從另一個大廳到達一個大廳任務的容器 (Reach one concourse task's container from another one)

從 Concourse 克隆 Bitbucket 上的 git 存儲庫的問題 (Issues cloning a git repo on Bitbucket from Concourse)

如果作業被取消,Concourse 會阻止後台進程停止 (Concourse prevent background processes from being stopped if job is canceled)

Concourse 流水線:如何讓嵌入式腳本使流水線失敗 (Concourse Pipeline: How to have an Embedded Script Fail the Pipeline)

將構建目錄 (/dist) 從一個作業傳遞到大廳中的下一個作業 (Pass build directory (/dist) from a job to next job in concourse)

Concourse CI 找不到 kubernetes 機密 (Concourse CI can't find kubernetes secrets)

大廳工作人員“找不到文件” (Concourse Worker "file not found")

windows系統需要安裝Concourse(CI/CD) (Need to Install Concourse(CI/CD) on windows system)

在管道任務中指定運行時參數 (Specify runtime parameter in a pipeline task)

如何遍歷大廳中的數組 (How to iterate through an array in concourse)







留言討論