【问题标题】:Pass build directory (/dist) from a job to next job in concourse将构建目录 (/dist) 从一个作业传递到大厅中的下一个作业
【发布时间】:2025-12-11 16:00:01
【问题描述】:

我知道这样做并不简单,并尝试探索了许多方法,但要么我无法正确理解它,要么不适合我。

我有一个运行 angular 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 文件夹。

【问题讨论】:

    标签: concourse concourse-pipeline


    【解决方案1】:

    我不太确定您为什么要为每个任务制定不同的计划定义,但这是做您想做的最简单的方法:

    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/
    

    通常您会将文件夹作为输入和输出在 TASKS 而不是 JOBS 之间传递(尽管有一些替代方案)

    Concourse 是无国籍状态,这就是它背后的理念。但是,如果你想在工作之间传递一些东西,唯一的方法是使用concourse resource 并取决于项目的性质,可以是从 git repo 到 s3 存储桶、docker 映像等的任何东西。你可以创建你自己的自定义资源。

    例如使用s3 concourse resource 之类的东西

    通过这种方式,您可以将工件推送到外部存储,然后在获取步骤的下一个作业中再次将其用作资源。但这可能会造成一些不必要的复杂性,即您想要做的事情非常简单

    根据我的经验,我发现有时大厅仪表板中工作计划的视觉方面给人的印象是工作计划应该是任务原子的,这并不总是需要

    希望对您有所帮助。

    【讨论】:

      最近更新 更多