簡體   English   中英

如何在 gitlab-ci 中使用 maven 分離測試和構建階段?

[英]How to separate test and build stage with maven in gitlab-ci?

我想將maven階段分開來buildtestdeploy

問題:我在這里把事情復雜化了嗎? 我是否應該只使用mvn clean package階段,因為compiletest是在package階段由 maven 隱式執行的?

.gitlab-ci.yml

stages:
  - build
  - test
  - deploy

build:
  stage: build
  script: mvn clean compile

test:
  stage: test
  script: mvn clean test

deploy:
  stage: deploy
  script: mvn clean package -Dmaven.test.skip=true
  #...continue with docker deployment...

帖子里有兩個問題。

如何在 gitlab-ci 中使用 maven 分離測試和構建階段?

這是可能的,並且可以像這樣完成,如GitLab maven 示例中所述:

image: maven:latest

variables:
  MAVEN_OPTS: >-
    -Dhttps.protocols=TLSv1.2
    -Dmaven.repo.local=.m2/repository
    -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN
    -Dorg.slf4j.simpleLogger.showDateTime=true
    -Djava.awt.headless=true

  MAVEN_CLI_OPTS: >-
    -s .gitlab-ci_settings.xml
    --batch-mode
    --errors
    --fail-at-end
    --show-version
    -DinstallAtEnd=true
    -DdeployAtEnd=true
    -Dstyle.color=always

cache:
  paths:
    - .m2/repository/
    - target/

mvn-compile-job:
  stage: mvn-compile
  script:
    - mvn $MAVEN_CLI_OPTS compile

mvn-test-job:
  stage: mvn-test
  script:
    - mvn $MAVEN_CLI_OPTS test

mvn-deploy-job:
  stage: mvn-deploy
  script:
    - mvn $MAVEN_CLI_OPTS deploy
  only:
    - master

問題:我在這里把事情復雜化了嗎?

這實際上取決於必須做什么以及您想實現什么。 例如,如果你想在不同的分支上運行不同的階段,這是一個很好的解決方案(在上面的例子中,我們只在 master 分支上運行mvn deploy )。

但是,與從一開始就運行mvn deploy相比,在單個分支上運行單獨的階段在 docker 運行器上需要更多時間,因為每個 GitLab 作業運行都需要圖像拉取。 這只是為 maven 存儲庫配置 CI/CD 時要考慮的事情。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM