I have a job that publishes to a private NPM repo.
The job is uses the NodeJS Plugin to provide an instance of node
To publish to NPM you need an .npmrc file specifying your auth token
In Jenkins configuration I have a managed file containing
//
registry.npmjs.org/:_authToken=$NPM_AUTH_TOKENwith the intention that $NPM_AUTH_TOKEN is injected as an environment variable
So under
BindingsI add it as a
Secret Textjust using the system node this works but using the NodeJS Plugin it doesn't
If under
Build Environment I
Inject environment variables to the build process
with the following groovy script
import jenkins.*
import jenkins.model.*
import com.cloudbees.plugins.credentials.Credentials
def credentials = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(com.cloudbees.plugins.credentials.Credentials.class);
def npm_creds =[:]
for (c in credentials) {
if (c.id == 'NPM_AUTH_TOKEN') { npm_creds = ['NPM_AUTH_TOKEN': c.secret]
}
}
return npm_creds
then the NodeJS plug does pick up the NPM_AUTH_TOKEN
Can anyone suggest either:
A simpler groovy script that just uses getCredentialById
or a simpler way for NodeJS to pick up the environment variable ?
TIA
Anthony