0

Following this article and using this help document, I am trying to get RabbitMQ started as a service for my job. The container starts, but the environment variable interpolation does not appear to be working.

Here is my workflow:

name: Test & Publish

on:
  push:
    branches: 
      - master

jobs:
  test:
    runs-on: ubuntu-latest

    services:
      rabbitmq:
        image: rabbitmq
        ports:
          - 5672/tcp
        env:
          RABBITMQ_USER: guest
          RABBITMQ_PASSWORD: guest
          RABBITMQ_VHOST: "/"

    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: 12
      - run: yarn
      - run: ./scripts/test-all.sh
        env:
          RABBITMQ_HOST: rabbitmq
          RABBITMQ_PORT: $❴❴ job.services.rabbitmq.ports['5672'] ❵❵

  publish-npm:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://registry.npmjs.org/
      - run: yarn
      - run: yarn semantic-release
        env:
          NODE_AUTH_TOKEN: ${{secrets.npm_token}}

The issue is RABBITMQ_PORT part. I modified my code to print out the value of

console.log(`amqp://${process.env.RABBITMQ_HOST}:${process.env.RABBITMQ_PORT}`)

... and I get this in the logs:

amqp://rabbitmq:$❴❴ job.services.rabbitmq.ports['5672'] ❵❵

... which is wrong. The RabbitMQ container seems to have started successfully, and I see it mapped the port: 5672/tcp -> 0.0.0.0:32768, so if the interpolation were correct, I would expect to see

amqp://rabbitmq:32768

Yet the docs don't appear to be doing the interpolation any differently than I am doing, so I'm confused as to what the issue is.

neezer
  • 790
  • 3
  • 10
  • 28

1 Answers1

0

My problem was copy/paste.

I pasted in

$❴❴ job.services.rabbitmq.ports['5672'] ❵❵

when it should've been

${{ job.services.rabbitmq.ports['5672'] }}

The curly braces are a different character code:

var first = '❴';
var second = '{';

console.log(`${first.charCodeAt(0)} is not the same as ${second.charCodeAt(0)}`);
//=> "10100 is not the same as 123"
neezer
  • 790
  • 3
  • 10
  • 28