Injecting environmental variables in build thats uses NodeJS Plugin

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Injecting environmental variables in build thats uses NodeJS Plugin

Anthony Green
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 getC
redentialById 

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 [hidden email].
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 | Threaded
Open this post in threaded view
|

Re: Injecting environmental variables in build thats uses NodeJS Plugin

Victor Martinez
Hi,

What about using https://wiki.jenkins.io/display/JENKINS/Mask+Passwords+Plugin? It might help you to create a global pass parameter to be used as an environment variable.

Cheers


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/07d1e656-e4bb-4ca2-9c0f-08353ba14f85%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.