Use exposed ENV variable from plugin as argument for another plugin

Hi everyone,

I’ve been trying to figure out a way to get my pipeline working for quite sometime, but no luck.

Basically I am using docker-compose to build the environment but due to be importing some private npm packages on my project, I need to pass the environment variable as an argument, but I can’t find a way to get it working.

Here is an example of the code and plugins I am trying to use.

- name: ":docker: :yarn: Build CI Container"
    key: build-ci
    plugins:
      - seek-oss/aws-sm#v2.3.1:
          env:
            NPM_TOKEN:
              secret-id: "arn:aws:secretsmanager:...."
              json-key: ".npm_token"
      - docker-compose#v3.8.0:
          build: ci
          image-repository: ....
          args:
            - "NPM_TOKEN=${NPM_TOKEN}"

seek-oss/aws-sm exposes the secret for me as an environment variable, but on docker-compose I need to use as an argument the NPM_TOKEN environment variable.

Hopefully someone can help me.

Cheers
Gus

I think you probably need to use the env key on the Docker Compose plugin (see the second example at GitHub - buildkite-plugins/docker-compose-buildkite-plugin: 🐳⚡️ Run build scripts, and build + push images, w/ Docker Compose).

@gus-asm Welcome to the community!

@cwmaier-grapl’s suggestion is correct, you’ll need to ensure that the values exposed in the seek-oss/aws-sm plugin are available to your containers using the env key in the example they provided there.

Thanks @jeremy and @cwmaier-grapl , I’ve tried initially using the env, but env are only used on run mode, not on build mode :(

` `env` or `environment` (optional, run only)

A list of either KEY or KEY=VALUE that are passed through as environment variables to the container.`

Is this another case of needing a double-dollar to stop the environment variable from being interpolated? Try:

          args:
            - "NPM_TOKEN=$$NPM_TOKEN"

…I’ve also ended up taking a whacky approach in Dockerfiles in the past, passing ARGs to ENVs. It pickles my noodle every time I have to think about it, but with enough time I can convince myself it makes sense. It goes something like:

ARG NPM_TOKEN
ENV NPM_TOKEN=$NPM_TOKEN

Don’t know if this will help, but give it a go - it could be useful one day anyway!