Hey,
I am experiencing random failures in my build because a secret is not set as an environment variable.
My setup is as follows:
I have a drone server on a low power machine, which should build my node projects
and then publish them to NPM.
The projects are hosted in a private gitea server, and the drone server waits for events from this.
The .core.yml looks as follows:
kind: pipeline
name: default
steps:
- name: install
image: node
environment:
NPM_TOKEN:
from_secret: npm_token
commands:
- npm install
- name: test
image: node
environment:
NPM_TOKEN:
from_secret: npm_token
commands:
- npm test
- name: build
image: node
environment:
NPM_TOKEN:
from_secret: npm_token
commands:
- npm run build
- name: publish
image: node
environment:
NPM_TOKEN:
from_secret: npm_token
commands:
- if [ "$(npm view @arwed/sanitize dist-tags.latest)" = "$(node -p -e "require('./package.json').version")" ]; then echo not publishing; else npm whoami & npm publish; fi
when:
branch:
- master
event:
exclude:
- pull_request
In the install step I get:
+ npm install
--
2 | Error: Failed to replace env in config: ${NPM_TOKEN}
3 | at /usr/local/lib/node_modules/npm/lib/config/core.js:415:13
4 | at String.replace (<anonymous>)
5 | at envReplace (/usr/local/lib/node_modules/npm/lib/config/core.js:411:12)
6 | at parseField (/usr/local/lib/node_modules/npm/lib/config/core.js:389:7)
7 | at /usr/local/lib/node_modules/npm/lib/config/core.js:330:24
8 | at Array.forEach (<anonymous>)
9 | at Conf.add (/usr/local/lib/node_modules/npm/lib/config/core.js:328:23)
10 | at ConfigChain.addString (/usr/local/lib/node_modules/npm/node_modules/config-chain/index.js:244:8)
11 | at Conf.<anonymous> (/usr/local/lib/node_modules/npm/lib/config/core.js:316:10)
12 | at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:90:16
13 | /usr/local/lib/node_modules/npm/lib/npm.js:59
14 | throw new Error('npm.load() required')
15 | ^
16 |
17 | Error: npm.load() required
18 | at Object.get (/usr/local/lib/node_modules/npm/lib/npm.js:59:13)
19 | at process.errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:205:32)
20 | at process.emit (events.js:197:13)
21 | at process._fatalException (internal/process/execution.js:127:25)
This implies that the environment variable NPM_TOKEN is not set.
This does not necessary happen randomly. It always happens when I open a pull request.
Thus always when the build says something like “Pfeifenjoy opened pull request #16 to master”.
Otherwise it works.