Concourse Pipeline配置子目录触发「not a valid repository name」报错咨询
问题核心定位
你遇到的not a valid repository name报错,根源是给frontend配置的Git资源URI完全不符合Git远程仓库的地址格式。
GitHub的SSH格式Git仓库地址规则为git@github.com:<组织名>/<仓库名>.git,冒号后面只能跟一级独立仓库的完整路径,不能嵌套仓库内的子目录路径。你写的git@github.com:test-repo/concourse-pipeline/frontend.git,会被Git客户端解析为“test-repo组织下,路径为concourse-pipeline/frontend.git的独立仓库”,这个仓库在平台侧根本不存在,自然会抛出仓库名无效的错误。
另外你的代码结构属于单仓库(Monorepo)模式:两个Angular应用、Node服务都是concourse-pipeline根仓库下的子目录,本身不是独立的远程Git仓库,根本不能单独为子目录配置指向子路径的Git资源。
排查验证步骤
- 本地直接执行你写的frontend资源对应的URI拉取命令
git clone git@github.com:test-repo/concourse-pipeline/frontend.git,会直接返回仓库不存在的报错,和流水线抛出的错误完全对应 - 对比其他能正常运行的资源:repo、run-server、version的URI都是正确指向根仓库
concourse-pipeline.git的,没有拼接子目录路径,所以可以正常拉取
正确配置方案
不需要为每个子目录建独立的Git远程仓库,利用Concourse Git资源内置的paths路径过滤能力,就能实现“子目录变更时触发对应流水线”的需求,整体配置调整如下:
资源配置调整
删掉之前错误的frontend独立Git资源,基于同一个根仓库,按目录拆分不同的路径监听资源:
resources: # 根仓库全量监听资源,用于版本号、全局构建任务 - name: repo type: git source: uri: git@github.com:test-repo/concourse-pipeline.git branch: master private_key: ((repo.private-key)) # 仅监听frontend目录变更的资源,替代之前错误的frontend资源 - name: frontend-changes type: git source: uri: git@github.com:test-repo/concourse-pipeline.git branch: master private_key: ((repo.private-key)) # 核心配置:只有frontend目录下的文件发生提交,才会更新这个资源、触发对应任务 paths: ["frontend/"] # 仅监听Node服务端目录变更的资源 - name: server-changes type: git source: uri: git@github.com:test-repo/concourse-pipeline.git branch: master private_key: ((repo.private-key)) paths: ["server/"] # 原有semver版本资源配置保留,无需修改 - name: version type: semver source: driver: git initial_version: 0.0.1 uri: git@github.com:test-repo/concourse-pipeline.git private_key: ((repo.private-key)) branch: master file: version
任务配置调整
将对应任务的触发源换成匹配的路径监听资源,通过输入路径映射保持原有任务命令的兼容性:
jobs: # 前端测试任务 - name: run-frontend build_logs_to_retain: 20 max_in_flight: 1 plan: - get: frontend-changes trigger: true - task: run-tests config: platform: linux image_resource: type: registry-image source: repository: node inputs: # 将拉取到的仓库内容重命名为frontend目录,适配原有命令 - name: frontend-changes path: frontend run: path: /bin/sh args: - -c - | echo "Node Version: $(node --version)" echo "NPM Version: $(npm --version)" cd frontend/frontend npm install ng test # 服务端测试任务 - name: run-server build_logs_to_retain: 20 max_in_flight: 1 plan: - get: server-changes trigger: true - task: run-tests config: platform: linux image_resource: type: registry-image source: repository: node inputs: - name: server-changes path: server run: path: /bin/sh args: - -c - | echo "Node Version: $(node --version)" echo "NPM Version: $(npm --version)" cd server/server npm install npm test # 以下版本号、全局构建任务保持原有逻辑不变 - name: bump-version plan: - get: repo trigger: true - put: version params: bump: patch - name: build-repo plan: - get: repo trigger: true - get: version params: build: repo tag_file: version tag_as_latest: true
注意事项
paths参数是Git资源自带的过滤能力,不需要额外安装插件,配置后资源依然会拉取完整的仓库代码,只是只会在匹配路径的提交发生时才更新资源版本、触发任务- 不需要为每个路径监听资源单独配置SSH私钥,所有资源都复用同一个仓库的访问权限,减少冗余配置
- 原来的配置中重复配置多个指向全仓库的Git资源,会导致任意目录的代码改动都触发所有关联任务,配合paths路径过滤后,可以实现精准的子目录触发,减少不必要的流水线运行成本
- 如果后续需要拆分独立仓库,只需要把对应子目录推到GitHub作为独立仓库,再把对应资源的URI换成新的仓库地址即可,任务逻辑不需要大改
内容的提问来源于stack exchange,提问作者user324534
相关产品推荐
相关产品推荐

