下列的本文并使用这个帮助文档,我正在尝试将 RabbitMQ 作为我的作业的服务启动。容器启动了,但环境变量插值似乎不起作用。
以下是我的工作流程:
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}}
问题是RABBITMQ_PORT
部分。我修改了我的代码来打印出
console.log(`amqp://${process.env.RABBITMQ_HOST}:${process.env.RABBITMQ_PORT}`)
...我在日志中看到了这个:
amqp://rabbitmq:$❴❴ job.services.rabbitmq.ports['5672'] ❵❵
... 这是错误的。RabbitMQ 容器似乎已成功启动,我看到它映射了端口:5672/tcp -> 0.0.0.0:32768
,因此如果插值正确,我希望看到
amqp://rabbitmq:32768
然而,文档所做的插值似乎与我所做的没有什么不同,所以我对问题是什么感到困惑。
答案1
我的问题是复制/粘贴。
我粘贴了
$❴❴ job.services.rabbitmq.ports['5672'] ❵❵
而这本该是
${{ job.services.rabbitmq.ports['5672'] }}
花括号是不同的字符代码:
var first = '❴';
var second = '{';
console.log(`${first.charCodeAt(0)} is not the same as ${second.charCodeAt(0)}`);
//=> "10100 is not the same as 123"