简体   繁体   English

从另一个项目克隆/使用.ps gitlab

[英]clone / use .ps from another project gitlab

I need use a few.ps1 from a project to make build and deploy in another.我需要使用一个项目中的几个.ps1 在另一个项目中进行构建和部署。 I try this:我试试这个:

repo with the.ps1 (its public and this repo have test2.ps1 and test3.ps1):带有.ps1 的回购(它的公共和这个回购有 test2.ps1 和 test3.ps1):

https://lgitlabn01vpr.xxx.com/user/test_clone https://lgitlabn01vpr.xxx.com/user/test_clone

and this is the repo that needs the script to build and deploy这是需要脚本来构建和部署的仓库

https://lgitlabn01vpr.xxx.com/mariano_prueba_2 https://lgitlabn01vpr.xxx.com/mariano_prueba_2

in "mariano_prueba_2" i have:在“mariano_prueba_2”中,我有:

dockerfile: 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

this mis my gitlab-ci.yml:这是我的 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_COMMIT_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_COMMIT_REF_NAME}.xxx.com

When i try with this, in the build stage say dont exist "example/test3.ps1".当我尝试这个时,在构建阶段说不存在“example/test3.ps1”。

Someone can help me with this or recommend another way?有人可以帮助我或推荐另一种方式吗?

thanks!谢谢!

All stages are independent of each other by default.默认情况下,所有阶段都是相互独立的。 This means you can not automatically rely on some output of the previous stage.这意味着你不能自动依赖上一阶段的一些output。 You need to manually tell GitLab CI that it should hand over those artifacts .您需要手动告诉 GitLab CI 它应该交出这些artifacts see https://docs.gitlab.com/ee/ci/yaml/#artifactshttps://docs.gitlab.com/ee/ci/yaml/#artifacts

in your case i would assume that the next lines would fix this.在您的情况下,我会假设下一行将解决此问题。

repo1 pull:
 stage: initialize
 script:
   - git clone https://lgitlabn01vpr.xxx.com/user/test_clone.git
 artifacts:
   paths:
     - test_clone

This should make the test_clone directory available within your sub projects.这应该使test_clone目录在您的子项目中可用。

Additionally you could also take a look at git submodules which is a perfect fit for this case:)此外,您还可以查看非常适合这种情况的git submodules :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM