ERROR: No files to upload

Hello,

I am trying to export the variable value (HAS_DESTROY_CHANGES) from one stage to another stage using artifacts:reports:dotenv method, but my pipeline is failing with the below error.

WARNING: Uploading artifacts as “dotenv” to coordinator… POST https://gitlab.build 400 Bad Request (Invalid Format) id=182245 responseStatus=400 Bad Request status=400 token=64_zESeE
WARNING: Retrying… context=artifacts-uploader error=invalid argument
WARNING: Uploading artifacts as “dotenv” to coordinator… POST https://gitlab.build 400 Bad Request (Invalid Format) id=182245 responseStatus=400 Bad Request status=400 token=64_zESeE
FATAL: invalid argument
Cleaning up project directory and file based variables
ERROR: Job failed: command terminated with exit code 1

Here is my pipeline code.

manual_approval:
  stage: manual_approval
  before_script:
  script:
    - terraform plan -input=false -out=tfplan
     - if terraform show tfplan | grep -q "No changes"; then echo "No changes"; HAS_DESTROY_CHANGES="false"; echo $HAS_DESTROY_CHANGES >> manual_approval.env; elif terraform show tfplan| grep -q "0 to change, 0 to destroy"; then echo "Changes with no destroys detected, it is safe for the pipeline to proceed automatically"; HAS_DESTROY_CHANGES="false"; echo $HAS_DESTROY_CHANGES >> manual_approval.env; else HAS_DESTROY_CHANGES="true"; echo $HAS_DESTROY_CHANGES >> manual_approval.env; fi
  artifacts:
    reports:
      dotenv: manual_approval.env  
wait_for_approval:
  stage: wait_for_approval
  when: manual
  script:
    - echo "$HAS_DESTROY_CHANGES"
  allow_failure: false 
  rules: 
    - if: ($HAS_DESTROY_CHANGES == "true")
  dependencies:
    - manual_approval
terraform_apply:
  stage: terraform_apply

You only echo value of the variable, not the name. So the content of your file is only

false

or

true

Your echo should be echo "HAS_DESTROY_CHANGES=$HAS_DESTROY_CHANGES"

Thanks @balonik for your replay. Could you please share some more details? Also do you have any suggestion how can export a variable from one stage to another stage and run based on a condition (or rule)

In your code replace echo $HAS_DESTROY_CHANGES >> manual_approval.env with echo "HAS_DESTROY_CHANGES=$HAS_DESTROY_CHANGES" >> manual_approval.env and it should work

1 Like

Hi @balonik , thanks a lot the first stage started working. but I noticed the second stage (wait_for_approval) is now not showing in the UI. It should trigger if only the values of HAS_DESTROY_CHANGES=true. But it is not showing in the UI even if the values are true. Any suggestion? thanks for your help.

ah, right. I missed your intention. You cannot use dotenv variables created in job scripts in rules, because rules are evaluated before any jobs run.

oh ok, but do you have any suggestion, how can I overcome this?

In pipelines? Probably not. You could probably make something like that work with dynamic child pipelines, but it won’t look nice.
Approvals like that are not really part of what GitLab does or aims to do. You should run a TF plan during open Merge Request where you will see the summary (changes) of TF plan directly in MR page. When the MR is approved and merged it’s equivalent of “approval” and pipeline to apply runs.

That is unfortunate and am stuck in the middle. But thanks for your help so far.

If anybody have any other suggestions or a better way to achieve then please update this thread, thank you