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_TOKEN

with the intention that $NPM_AUTH_TOKEN is injected as an environment 
variable

So under *Bindings*

I add it as a *Secret Text*

just 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


-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/0023c33f-a283-4d06-9d9c-96d3c1d5669b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to