我需要使用一个项目中的一些 .ps1 来在另一个项目中进行构建和部署。我试试这个:
带有 .ps1 的 repo(它的 public 和这个 repo 有 test2.ps1 和 test3.ps1):
https://lgitlabn01vpr.xxx.com/user/test_clone
这是需要脚本来构建和部署的存储库
https://lgitlabn01vpr.xxx.com/mariano_prueba_2
在“mariano_prueba_2”中我有:
dockerfile:
FROM registryn01vpr.xxx.com/devops/windows_containers/iis_images/iis10_net4_5_ora12_2:latest
SHELL [ "powershell" ]
COPY example/test3.ps1 c:/
EXPOSE 80
这是我的 gitlab-ci.yml:
image: docker:latest
stages:
- initialize
- build
- deploy
repo1 pull:
stage: initialize
script:
- git clone https://lgitlabn01vpr.xxx.com/user/test_clone.git
variables:
DOCKER_DRIVER: overlay2
services:
- docker:dind
cache:
key: "$CI_BUILD_REF_NAME"
untracked: true
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build-master:
stage: build
script:
- cp test_clone/ example/
- docker build --cache-from "$CI_REGISTRY/$CI_PROJECT_PATH/$CI_COMMIT_BRANCH" -t "$CI_REGISTRY/$CI_PROJECT_PATH/$CI_COMMIT_BRANCH" .
- docker push "$CI_REGISTRY/$CI_PROJECT_PATH/$CI_COMMIT_BRANCH"
deploy-to-swarm-develop:
stage: deploy
when: manual
variables:
DOCKER_HOST: "$CI_DOCKER_HOST_TEST"
SERVICE_NAME: "$CI_PROJECT_NAME"
CI_CARPETAS_PASSWD: "$CI_CARPETAS_PASSWD"
CI_CARPETAS_USER: "$CI_CARPETAS_USER"
image: docker:latest
2 script:
- powershell -File test2.ps1 ${CI_CARPETAS_USER} ${CI_CARPETAS_PASSWD}
- docker stack deploy --with-registry-auth --compose-file=docker-stack-compose-test.yml ${SERVICE_NAME}
environment:
name: develop
url: http://${CI_BUILD_REF_NAME}.xxx.com
当我尝试这个时,在构建阶段说不存在“example/test3.ps1”。
有人可以帮我解决这个问题或推荐其他方法吗?
谢谢!
答案 0 :(得分:0)
默认情况下,所有阶段都是相互独立的。这意味着您不能自动依赖前一阶段的某些输出。您需要手动告诉 GitLab CI 它应该移交那些 artifacts
。见https://docs.gitlab.com/ee/ci/yaml/#artifacts
在你的情况下,我会假设下一行会解决这个问题。
repo1 pull:
stage: initialize
script:
- git clone https://lgitlabn01vpr.xxx.com/user/test_clone.git
artifacts:
paths:
- test_clone
这将使 test_clone
目录在您的子项目中可用。
此外,您还可以查看 git submodules
,它非常适合这种情况:)