Injecting environmental variables in build thats uses NodeJS Plugin

2017-11-29 Thread 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 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 jenkinsci-users+unsubscr...@googlegroups.com.
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.


Re: Adding User permissions with groovy

2015-08-20 Thread Anthony Green


On Thursday, 20 August 2015 13:47:05 UTC+1, Anthony Green wrote:
>
> This was my solution
>
> import jenkins.model.*
> import hudson.security.*
>
> def instance = Jenkins.getInstance()
>
> def strategy = new GlobalMatrixAuthorizationStrategy()
> strategy.add(Jenkins.ADMINISTER, "foo")
> strategy.add(Jenkins.READ, 'baz')
> strategy.add(Item.DISCOVER, 'baz')
> strategy.add(Item.READ, 'baz')
> strategy.add(Item.BUILD, 'baz')
>
> instance.setAuthorizationStrategy(strategy)
>
> instance.save()
>
>
Actually although this worked in the script console it doesn't work in 
init.groovy.d 

you get the error

Failed to run script 
file:/var/jenkins_home/init.groovy.d/ConfigureSecurity.groovy
groovy.lang.MissingPropertyException: No such property: Item for class: 
ConfigureSecurity
at 
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
at 
org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)

restarting jenkins and the settings are applied.

Any pointers as to what's going wrong? 

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/c5051ada-198b-4f44-8adb-479ce6328b3b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding User permissions with groovy

2015-08-20 Thread Anthony Green
This was my solution

import jenkins.model.*
import hudson.security.*

def instance = Jenkins.getInstance()

def strategy = new GlobalMatrixAuthorizationStrategy()
strategy.add(Jenkins.ADMINISTER, "foo")
strategy.add(Jenkins.READ, 'baz')
strategy.add(Item.DISCOVER, 'baz')
strategy.add(Item.READ, 'baz')
strategy.add(Item.BUILD, 'baz')

instance.setAuthorizationStrategy(strategy)

instance.save()

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/061670e0-5bb3-4bec-8172-a6c0174384d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Adding User permissions with groovy

2015-08-20 Thread Anthony Green
Has anyone managed to script the authorisation levels of a user with Groovy?

I have the beginnings of a script:

import jenkins.model.*
import hudson.security.*

def instance = Jenkins.getInstance()
def hudsonRealm = new HudsonPrivateSecurityRealm(false)

instance.setSecurityRealm(hudsonRealm)

hudsonRealm.createAccount("admin_username", "admin_password")
hudsonRealm.createAccount("developer_username", "developer_password")

def adminStrategy = new GlobalMatrixAuthorizationStrategy()
adminStrategy.add(Jenkins.ADMINISTER, "admin_username")

instance.setAuthorizationStrategy(adminStrategy)

instance.save()


but I can't figure out how to add READ permissions for the user 'developer'

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/f51b32d2-a1e2-4f26-a20a-c76cf615ca7f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Invoking top-level Maven targets on a slave

2015-07-22 Thread Anthony Green
On Tuesday, 21 July 2015 13:21:37 UTC+1, Anthony Green wrote:
>
> I''m running a Jenkins Ubuntu Master with an OS X Slave
>
> I can't get a build step "Invoking top-level Maven targets" to run on a 
> slave.
>
> I get a 
>
> FATAL: command execution failed
>
> java.io.IOException 
> <http://stacktrace.jenkins-ci.org/search?query=java.io.IOException>: Cannot 
> run program "mvn"
>
>
Could the cause be this open Jenkins bug?

https://issues.jenkins-ci.org/browse/JENKINS-3474 

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/42807aae-d2e5-452f-bd8d-35aedf96e647%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Invoking top-level Maven targets on a slave

2015-07-21 Thread Anthony Green
I''m running a Jenkins Ubuntu Master with an OS X Slave

I can't get a build step "Invoking top-level Maven targets" to run on a 
slave.

I get a 

FATAL: command execution failed

java.io.IOException 
: Cannot run 
program "mvn"

I've tried setting environment variables and that works for a shell script 
build step but not a Maven build step.
I've tried setting Tool Locations on the slave to point at the slave's Maven 
installation and that doesn't work.

How is this supposed to be accomplished? 

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/92f3f50e-b18e-4f82-a437-219c968d9957%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tool locations dropdown empty

2015-07-20 Thread Anthony Green
On Monday, 20 July 2015 14:26:10 UTC+1, Daniel Beck wrote:
>
> You need to configure tools first in Manage Jenkins » Configure Jenkins. 
>
> That dropdown is also empty 

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/69b4e1ec-ff18-41d8-9509-ee17838b475e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Tool locations dropdown empty

2015-07-20 Thread Anthony Green
I want to customise the tool locations of my Jenkins Slaves 
However when I click add to the List of tool locations the 'Name' dropdown 
menu is empty.

Is this a bug or is the a pre-step I've missed out?

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/54f62439-95a4-4d89-b56f-f963c2cebd2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Jenkins-cli never respond

2015-06-26 Thread Anthony Green

>
>
> Everybody is right :)  The CLI client automatically discovers the JNLP 
> port and communicates via that.  So, as Richard mentions, you don't need 
> to know the JNLP port — you just provide the regular Jenkins web URL 
> when running the CLI client command. 
>

Except perhaps your containerising it with Docker and then you have to port 
forward from the host to the container ?

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/7fdabe39-03c8-47d3-9035-55b439140f1f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Jenkins-cli never respond

2015-06-25 Thread Anthony Green


On Wednesday, 24 June 2015 10:38:05 UTC+1, Richard Bywater wrote:
>
> The CLI doesn't use the JNLP port - you need to point it at the normal web 
> port (e.g. 8080)
>>
>>
>>
Are you sure? What I've read regarding setting up Jenkins in a Docker 
suggests that's exactly what it uses.

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/d77c4ab3-d808-493b-85bb-14ef7dbf49a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Fixing TCP port for JNLP slave agents from command line

2015-06-25 Thread Anthony Green
On Thursday, 25 June 2015 12:03:30 UTC+1, Anthony Green wrote:
>
> Can it be done via the CLI or with curl as a POST request? 
>

I've experimented with a POST request 

curl -X POST -d 
'.useSecurity=on&slaveAgentPort.type=fixed&value=2230&core%3Aapply=true&json=%7B%22useSecurity%22%3A+%7B%22slaveAgentPort%22%3A+%7B%22type%22%3A+%22fixed%22%2C+%22value%22%3A+%30%22%7D%7D%2C+%22core%3Aapply%22%3A+%22true%22%7D'
 
--header 'Content-Type: application/x-www-form-urlencoded' 
http://localhost:8080//configureSecurity/configure 

This does set the port to a fixed number

Don't know if there's a better way 

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/c6447d94-34a1-41a1-9a5b-f4008e04195b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Fixing TCP port for JNLP slave agents from command line

2015-06-25 Thread Anthony Green


On Thursday, 25 June 2015 10:14:56 UTC+1, Vincent Latombe wrote:
>
> Hi,
>
> this can be configured under Manage Jenkins > Configure global security.
>
> Vincent
>

That's not from the command line. 

Can it be done via the CLI or with curl as a POST request? 
Has anyone scripted it?

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/389d0ce1-a327-4acc-832b-61e21ab2e8d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Fixing TCP port for JNLP slave agents from command line

2015-06-25 Thread Anthony Green
Is it possible to fix the TCP port for JNLP slave agents from command line?
I'm trying to automated the installation and configuration of Jenkins, in a 
Docker container, via Ansible and am trying to use the Jenkins CLI to 
install the job-dsl plugin.

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/a557f1b1-3810-4651-bfdc-c07c4e02028e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Jenkins CLI not working OSX

2015-06-22 Thread Anthony Green
On Monday, 22 June 2015 10:14:55 UTC+1, Richard Bywater wrote:
>
> I assume Jenkins has been started? (Not sure if downloading via Homebrew 
> automatically starts it)
>
> Richard
>

Jenkins is running, responding 200 to http requests 

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/ab2b354d-5429-4cdd-a8fb-972ec334e814%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Jenkins CLI not working OSX

2015-06-22 Thread Anthony Green
Steps to reproduce

1. Install Jenkins via Homebrew
2. Download jenkins-cli.jar -
3. run

java -jar jenkins-cli.jar -s http://localhost:8080/ help

response:

Enter passphrase for /Users/jenkins/.ssh/id_rsa:

Exception in thread "main" java.io.IOException: There's no Jenkins running 
at http://localhost:8080/

at hudson.cli.CLI.getCliTcpPort(CLI.java:281)

at hudson.cli.CLI.(CLI.java:126)

at hudson.cli.CLIConnectionFactory.connect(CLIConnectionFactory.java:72)

at hudson.cli.CLI._main(CLI.java:466)

at hudson.cli.CLI.main(CLI.java:382)

Suppressed: java.net.SocketException: Connection reset

 at java.net.SocketInputStream.read(SocketInputStream.java:209)

 at java.net.SocketInputStream.read(SocketInputStream.java:141)

 at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)

 at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)

 at java.io.BufferedInputStream.read(BufferedInputStream.java:345)

 at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704)

 at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)

 at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:675)

 at 
sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1535)

 at 
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)

 at hudson.cli.FullDuplexHttpStream.(FullDuplexHttpStream.java:78)

 at hudson.cli.CLI.connectViaHttp(CLI.java:156)

 at hudson.cli.CLI.(CLI.java:130)

 ... 3 more

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/46df016d-9e73-4912-bcb5-e5f8eec95367%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.