简体   繁体   中英

download artifacts between pipelines in the same project Gitlab ci

I am currently running 2 jobs. One running some test unit which generate a coverage.xml file from php based project and another which launch a sonarqube analysis based on that coverage file.

Here is the gitlab-ci.yml:

stages:
  - tests
  - sonar
    tests:
      stage: "tests"
      image: some-image
      only:
        - merge_requests
      script:
         - script.sh
      artifacts:
        paths:
          - var/php/xml/coverage.xml
    
    sonarqube-scanner:
      stage: "sonar"
      only:
        - specific_branch
      image:
        name: sonarsource/sonar-scanner-cli:latest
      cache:
        key: ${CI_JOB_NAME}
        paths:
          - .sonar/cache
      script:
        - sonar-scanner -Dsonar.php.coverage.reportPaths=#with_some_parameters
      allow_failure: false
      dependencies:
        - tests

When i run those 2 jobs with the same only condition ( both with only condition set to a specific branch) the sonar job can retrieve the artefact without any problem

As soon as i put different only condition between those 2 jobs, which is only in merge requests for my unit test and only in a specific branch for my sonar scan. In the case where the merge request is not in the same branch as the branch specify in the sonar only conditions. the sonar job is not able to retrieve the artefact.

Is there any way to pass an artefact from one job to another that have different only conditions?

Thanks in advance

Is there any way to pass an artefact from one job to another that have different only conditions?

Actually the conditions itself do not matter, as long as they both evaluate to letting the job run.

In the case where the merge request is not in the same branch as the branch specify in the sonar only conditions. the sonar job is not able to retrieve the artefact.

If it's not the branch as specified in the only condition, the sonarqube-scanner job won't run actually… Are you sure that the sonarqube-scanner job is really triggered?

As long as the dependency's "only" clause will ALWAYS include the only clause of the dependent, it should run. In other words, something like tests run on all merge requests and sonar only runs on some merge requests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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