Search code examples
gitgitlabgitlab-cipipelinecicd

Send .txt output of a GitLab CICD pipeline to artifact module


I am using GitLab to execute a script, which generates a .txt file. I need to then get that file to export as an artifact using the GitLab artefact module.

Below is the cicd pipeline:

stages:
  - run

variables:
  VAULT_ADDR: https://vault:800


build:
    stage: run
    image:
      name: nexus.service:840/terraform:stable
      entrypoint:
        - '/usr/bin/env'
        - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
    only: 
      -  master
    script:
        - export AWS_ACCESS_KEY_ID="$(vault read -field=value secret/aws/aws_access_key)"
        - export AWS_SECRET_ACCESS_KEY="$(vault read -field=value secret/aws/aws_secret_key)"
        - ./src/GetFunction.sh

Below is the .sh script that the pipeline runs:

#!/bin/bash
aws \
    resourcegroupstaggingapi \
    get-resources \
    --resource-type-filters "lambda" \
    | jq -r '.ResourceTagMappingList[] | [.ResourceARN, ((.Tags | map([.Key, .Value] | join("="))) | join(","))] | @csv' > Lambda.txt 

I've tried adding in the artifact module like below, but not having any luck and the job is failing. Without the artifact module, the job runs ok but I am unable to retrieve a .txt file.

    artifacts:
    paths:
      - Lambda.txt

Any idea? I think the artifact module might be overkill for what I am trying to achieve.


Solution

  • So this was resolved by fixing one issue and implementing the artifact module properly.

    In the .sh script there was one section missing, so the output .txt file wasn't being created. The missing part was a specified region:

    --region

    Then the artifact section needed to change to:

    artifacts:
      name: Lambda.txt
      paths:
        - Lambda.txt