Env var mismatch

Hi,
I have a use-case where I need to post the coverage-report as a Github comment on the PR.
I am using a GITHUB_COMMENT env var and assigning it a placeholder value which would later be modified to be the code-coverage report value.

There seems to be a value mismatch in the Buildkite Step for the env var.
Echo value of GITHUB_COMMENT =
### CODE COVERAGE FOR NEST
total: (statements) 81.5%

Value in env command = "Template comment"

Can someone pls look into this ?
Why is the export command not able to modify the value of the var.

Link to build → https://buildkite.com/equinix/ngo-engineering/builds/1153#_

Thanks in advance.

env:
  GITHUB_COMMENT: "Template comment"

 - label: ":shrek: Report coverage comment on PR"
    key: "report-coverage-comment-on-pr"
    depends_on: ["retreive-code-coverage-artifacts"]
    commands: |
      #!/usr/bin/env bash
      set -euo pipefail
      echo --- Retrieve artifacts
      buildkite-agent artifact download "code_coverage_summary.md" .
      export GITHUB_COMMENT=$(cat code_coverage_summary.md)
      echo "\$GITHUB_COMMENT"

      echo "Token equals: $${GITHUB_TOKEN}"

    plugins:
      - ssh://git@github.com/packethost/ssm-buildkite-plugin#v1.0.4:
          parameters:
            GITHUB_TOKEN: /buildkite/ngo/GITHUB_PAT/v3   

      - telefonica/github-pr-comment#0.0.5:
          comment: ${GITHUB_COMMENT}
          pr: ${BUILDKITE_PULL_REQUEST} # Optional, PR Number to add the comment
          repo: ${BUILDKITE_PULL_REQUEST_REPO} # Optional, format git://github.com:user/repo.git)```

Hey @farhan :wave: good question! So the value of $GITHUB_COMMENT is exported during the command run time, but because you’ve interpolated the value of comment during the pipeline upload, it will use the value set in the top level env block in that YAML. To get the correct value you should be able to use this as your plugin config:

- telefonica/github-pr-comment#0.0.5:
          comment: $${GITHUB_COMMENT}
          pr: ${BUILDKITE_PULL_REQUEST} # Optional, PR Number to add the comment
          repo: ${BUILDKITE_PULL_REQUEST_REPO} # Optional, format git://github.com:user/repo.git)

Which will tell the plugin to use the value of $GITHUB_COMMENT during the plugin execution, rather than what the plugin receives as a hardcoded string Template comment .

Hopefully that helps, but let us know if you have any other questions :slightly_smiling_face:

Hi @jeremy.
Posting the update here as well for users with the same issue.

The plugin does not support passing the env var as attributes.

The work around for me was creating a custom version of the hooks that supports passing env var as attributes.

Thanks a lot for your guidance !!

1 Like