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


問題描述

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

據我搜索,我沒有看到任何有關 Concourse CI 的循環和數組的文檔。

我正在嘗試將作業從 Jenkins 遷移到 CI 和我的 Jenkins 的片段文件

def folders = [
"roller",
"auth",
"Django",
"gitlab",
"Drone",

]
stage('tests & conv') {
when {
beforeAgent true
not {
branch 'master'
}
}
steps {
script {
parallel folders.collectEntries {
[
"tests ${i}" : {
stage("Test ${i}") {
sh "make ${i}"
}
},
"conv ${it}" : {
stage("Test ${i}") {
sh "make run ${i} "
}
},
]
}
}
}
}
</code></pre>

如何在 Concourse 管道中復制相同的文件。

我可以定義如下數組,但不確定如何遍歷它們。

folders:
  ‑ roller
  ‑ auth
  ‑ Django
  ‑ gitlab
  ‑ Drone


參考解法

方法 1:

This may not be the complete answer but should definitely start you off running in the right direction. You can in effect do what you need using Carvel YTT which automates the YAML creation. There is also a very handy playground on that site where you can check your workings, and it will show you what the generated YAML will look like.

Example vars.yaml:

#@data/values
‑‑‑
folders:
 ‑ name: roller
 ‑ name: auth
 ‑ name: Django
 ‑ name: gitlab
 ‑ name: Drone‑runtime

Example schema.yaml would then be:

#@data/values‑schema
‑‑‑
folders:
 ‑ name: ""

Your starting concourse Carvel‑ytt pipeline.yaml could be:

<code>#@ load("@ytt:data", "data")

@ load("@ytt:struct", "struct")

@ folders = []

@ for f in data.values.folders:

@ folders.append(struct.make(name = f.name))

@ end

@ def task_make(folder):

task: #@ folder.name + "make‑task"
image: alpine
config:
platform: linux
params:
NAME: #@ folder.name
run:
path: /bin/sh
user: root
args:
‑ ‑exec
‑ |
make "$NAME"

@ end

@ def task_make_run(folder):

task: #@ folder.name + "make‑run‑task"
image: alpine
config:
platform: linux
params:
NAME: #@ folder.name
run:
path: /bin/sh
user: root
args:
‑ ‑exec
‑ |
make run "$NAME"

@ end

@ def job(folder):

name: #@ folder.name
plan:
‑ get: alpine
‑ #@ task_make(folder)
‑ #@ task_make_run(folder)

@ end

resources:
‑ name: ytt
type: registry‑image
source:
repository: taylorsilva/carvel‑ytt
tag: 0.36
‑ name: cicd‑source
type: git
icon: bitbucket
source:
uri: ((git‑source‑ssh‑url))/((this‑repo)).git
branch: main
private_key: ((key.git‑key))
‑ name: alpine
type: registry‑image
icon: docker
source:
repository: alpine
tag: '3.15.5'

jobs:
‑ name: configure‑self
plan:
‑ in_parallel:
‑ get: ytt
‑ get: cicd‑source
trigger: true
‑ task: generate‑jobs
image: ytt
config:
platform: linux
inputs:
‑ name: ci‑source
outputs:
‑ name: pipeline
run:
path: /bin/sh
user: root
args:
‑ ‑exc
‑ |
ytt ‑f ./cicd‑source ‑‑output‑files pipeline
‑ set_pipeline: job‑manager
file: pipeline/pipeline.yaml

@ for folder in data.values.folders:

‑ #@ job(folder)

@ end

</code></pre>

Now in the pipeline.yaml there is a lot going on here that is out of scope of your OP, but pretty neat. We use taylorsilva's carvel‑ytt image and this creates the pipeline.yaml that we point the concourse set‑pipeline command to generate the all the jobs. This self‑configure job will automatically trigger and update itself when you update its SCM. If you have any secret management set up then you can substitute the ((variable references)), otherwise replace them directly with what you need.

  • Note: that you may need to change the commands run in the tasks depending on your need.
  • Note: You should update your images to pull from a local repository rather than direct from dockerhub each time.

(by Chel MSbearddha)

參考文件

  1. How to iterate through an array in concourse (CC BY‑SA 2.5/3.0/4.0)

#concourse #yaml #concourse-task






相關問題

進行飛行同步時的未知目標 (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)







留言討論