Jfrog Pipelines能否禁用并发运行?如何让Run 2等待Run 1完成?
Jfrog Pipelines 并发控制与任务依赖实现
一、是否可以禁用并发运行?
可以。Jfrog Pipelines提供两种核心方式实现并发禁用:
1. 配置Pipeline并发限制参数
直接在Pipeline定义中添加concurrencyLimit并设置为1,即可限制该Pipeline同时仅能执行一个Run,后续触发的Run会自动进入等待队列,直到当前Run执行完成。
pipelines: - name: MyRestrictedPipeline concurrencyLimit: 1 steps: - name: CoreExecutionStep type: Bash execution: onExecute: - echo "Executing pipeline step with no concurrency..."
2. 使用全局资源锁
定义一个共享的Lock资源,所有需要串行执行的Pipeline Run都会抢占该锁,只有获取锁的Run才能启动,其他Run会等待锁释放后再执行。这种方式适用于跨Pipeline的全局串行控制场景。
resources: - name: GlobalPipelineLock type: Lock configuration: lockName: "cross-pipeline-serial-lock" lockTimeout: 3600 # 锁超时时间,单位秒 pipelines: - name: SerialPipeline steps: - name: LockProtectedStep type: Bash configuration: inputResources: - name: GlobalPipelineLock execution: onExecute: - echo "Running step with global lock protection..."
二、让Run 2等待Run 1执行完成后启动
根据Run所属场景,有不同实现方式:
1. 同一Pipeline的两个Run
直接使用上述的concurrencyLimit: 1或全局资源锁即可,新触发的Run 2会自动等待Run 1执行完成后启动。
2. 不同Pipeline的两个Run
通过资源触发+依赖实现跨Pipeline的串行执行:
- 第一步:在Run 1所属的Pipeline中,配置一个输出资源(如
File或BuildInfo),在Run 1执行完成后更新该资源。 - 第二步:在Run 2所属的Pipeline中,添加资源触发器,监听上述输出资源的更新事件,当资源被Run 1更新后,自动触发Run 2执行。
示例配置:
Run 1所属Pipeline(Pipeline A)
resources: - name: PipelineATriggerResource type: File configuration: sourceArtifactory: MyArtifactoryInstance path: "generic/trigger/pipeline-a-complete.txt" pipelines: - name: PipelineA steps: - name: Run1Execution type: Bash execution: onExecute: - echo "Run 1 is executing..." # 执行完成后更新触发资源 - echo "$(date) Run1 completed" > trigger.txt - rt_upload trigger.txt "generic/trigger/pipeline-a-complete.txt" outputResources: - name: PipelineATriggerResource
Run 2所属Pipeline(Pipeline B)
resources: - name: PipelineATriggerResource type: File configuration: sourceArtifactory: MyArtifactoryInstance path: "generic/trigger/pipeline-a-complete.txt" pipelines: - name: PipelineB triggers: - name: TriggerOnRun1Complete type: Resource configuration: resource: PipelineATriggerResource condition: "updated" # 资源有新版本时触发 steps: - name: Run2Execution type: Bash inputResources: - name: PipelineATriggerResource execution: onExecute: - echo "Run 2 is executing after Run 1 completed..."
3. 同一Pipeline中的两个步骤(单Run内的串行)
如果是同一个Run里的两个步骤需要串行,直接通过dependsOn参数设置步骤依赖即可:
pipelines: - name: SingleRunSerialPipeline steps: - name: Run1Step type: Bash execution: onExecute: - echo "Executing Run 1 step..." - name: Run2Step type: Bash configuration: dependsOn: - Run1Step execution: onExecute: - echo "Executing Run 2 step after Run 1 step finished..."
内容的提问来源于stack exchange,提问作者Abhishek
相关产品推荐
相关产品推荐

