PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 9, 2022

[FIXED] How return artifact from Child Job to Parent pipeline?

 October 09, 2022     cicd, continuous-delivery, continuous-deployment, gitlab-ci     No comments   

Issue

Use trigger for dynamic select test job

prepare_test:
  image: $CI_REGISTRY/platform/docker-images/vault:1.8
  variables:
    CONTEXT_TEST: |
      include:
      # PRODUCT
        - project: 'gitlabci/integration-test'
          ref: dev_v2
          file: 
            - 'spark/.base_integration_test.yml'
            - 'spark/.base_integration_test_with_kafka.yml'   
      integration_test:
        variables:
          COVERAGE_SOURCE: "./src"  
    INTEGRATION_TEST: |
      $CONTEXT_TEST
        extends: .base_integration_test
    INTEGRATION_TEST_WITH_KAFKA: |
      $CONTEXT_TEST 
        extends: .base_integration_test_with_kafka  
  stage: prepare_test
  script:
    - export CICD_KAFKA_HOST=$(cat test/fixtures.py | grep KAFKA_HOST)
    - >
      if [ "$CICD_KAFKA_HOST" != "" ]; then
        export CICD_KAFKA_HOST="true"
        echo "$INTEGRATION_TEST_WITH_KAFKA" >> test.yml
      else
        export CICD_KAFKA_HOST="false"
        echo "$INTEGRATION_TEST" >> test.yml
      fi
    - env | sort -f
  artifacts:
    paths:
      - test.yml
    expire_in: 6000 seconds


# --------------- Integration test --------------- ###
integration_test:
  stage: test 
  trigger:
    include:
      - artifact: test.yml
        job: prepare_test
    strategy: depend

enter image description here

after complete child integration_test create coverage-report.xml

How return coverage-report.xml to parent pipeline?


Solution

You can use Gitlab API:

my-job:
  image: ...
  stage: ...
  script:
    - >
        export CI_CHILD_PIPELINE_ID=$(curl --header "PRIVATE-TOKEN: $GITLAB_USER_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/pipelines/$CI_PIPELINE_ID/bridges" | jq ".[].downstream_pipeline.id")
    - echo $CI_CHILD_PIPELINE_ID
    - >
        export CI_CHILD_JOB_ID=$(curl --header "PRIVATE-TOKEN: $GITLAB_USER_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/pipelines/$CI_CHILD_PIPELINE_ID/jobs" | jq '.[].id')
    - echo $CI_CHILD_JOB_ID 
    - 'curl --output artifacts.zip --header "PRIVATE-TOKEN: $GITLAB_USER_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/jobs/$CI_CHILD_JOB_ID/artifacts"'
    - unzip artifacts.zip


Answered By - Philippe GRANET
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing