Jenkins 1.519 and Active Directory plugin 1.33 have the same/similar issue. I'm on Windows 2008 R2, and I see that the REST API access doesn't work w/the apiToken. I have to supply the user's username and password in the REST API request. From here: https://wiki.jenkins-ci.org/display/JENKINS/Authenticating+scripted+clients when I run the wget request sample, it fails w/a clear message that it is querying AD for the wrong username.
Here is a wget debug trace of a failed request:
============================ start of trace
C:\gnuwin32\bin> .\wget.exe --auth-no-challenge --http-user=user --http-password=apiToken http://myserver.com:8080/job/Experiment-Main-Build/build?token=1715b88bfba6717fadee72f5d5ecd17a
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\gnuwin32/etc/wgetrc
-2013-11-13 16:10:34- http://myserver.com:8080/job/Experiment-Main-Build/build?token=1715b88bfba6717fadee72f5d5ecd17a
Resolving myserver.com... 172.19.72.148
Connecting to myserver.com|172.19.72.148|:8080... connected.
HTTP request sent, awaiting response... 401 Authorization Required
Authorization failed.
PS C:\gnuwin32\bin> .\wget.exe --auth-no-challenge --http-user=user --http-password=apiToken http://myserver.com:8080/job/Experiment-Main-Build/build?token=1715b88bfba6717fadee72f5d5ecd17a --debug
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\gnuwin32/etc/wgetrc
DEBUG output created by Wget 1.11.4 on Windows-MinGW.
-2013-11-13 16:11:07- http://myserver.com:8080/job/Experiment-Main-Build/build?token=1715b88bfba6717fadee72f5d5ecd17a
Auth-without-challenge set, sending Basic credentials.
Resolving myserver.com... seconds 0.00, 172.19.72.148
Caching myserver.com => 172.19.72.148
Connecting to myserver.com|172.19.72.148|:8080... seconds 0.00, connected.
Created socket 300.
Releasing 0x0056b108 (new refcount 1).
--request begin--
GET /job/Experiment-Main-Build/build?token=1715b88bfba6717fadee72f5d5ecd17a HTTP/1.0
User-Agent: Wget/1.11.4
Accept: /
Authorization: Basic dXNlcjphcGlUb2tlbg==
Host: myserver.com:8080
Connection: Keep-Alive
--request end--
HTTP request sent, awaiting response...
--response begin--
HTTP/1.0 401 Authorization Required
Server: Winstone Servlet Engine v0.9.10
WWW-Authenticate: Basic realm="Jenkins"
Content-Length: 505
Connection: Keep-Alive
Content-Type: text/html;charset=ISO-8859-1
Date: Wed, 13 Nov 2013 23:11:07 GMT
X-Powered-By: Servlet/2.5 (Winstone/0.9.10)
--response end--
401 Authorization Required
Registered socket 300 for persistent reuse.
Skipping 505 bytes of body: [<html><head><title>Error 401</title></head><body bgcolor="#ffffff"><h1>Status Code: 401</h1>Exception: Either no such user 'user@myserver.com' or incorrect password; nested exception is javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 52e, v1db1] done.
Authorization failed.
============================ end of trace
and here is a successful request using username and password:
============================ start of trace
C:\gnuwin32\bin> .\wget.exe --auth-no-challenge --http-user=jburke --http-password="mypassword" http://myserver.com:8080/job/Experiment-Main-Build/build?token=1715b88bfba6717fadee72f5d5ecd17a --debug
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\gnuwin32/etc/wgetrc
DEBUG output created by Wget 1.11.4 on Windows-MinGW.
-2013-11-13 17:25:39- http://myserver.com:8080/job/Experiment-Main-Build/build?token=1715b88bfba6717fadee72f5d5ecd17a
Auth-without-challenge set, sending Basic credentials.
Resolving myserver.com... seconds 0.00, 172.19.72.148
Caching myserver.com => 172.19.72.148
Connecting to myserver.com|172.19.72.148|:8080... seconds 0.00, connected.
Created socket 300.
Releasing 0x0049ef78 (new refcount 1).
--request begin--
GET /job/Experiment-Main-Build/build?token=1715b88bfba6717fadee72f5d5ecd17a HTTP/1.0
User-Agent: Wget/1.11.4
Accept: /
Authorization: Basic amJ1cmtlOmEsTWlydGg7OA==
Host: myserver.com:8080
Connection: Keep-Alive
--request end--
HTTP request sent, awaiting response...
--response begin--
HTTP/1.0 200 OK
Server: Winstone Servlet Engine v0.9.10
Expires: 0
Cache-Control: no-cache,must-revalidate
X-Hudson-Theme: default
Content-Type: text/html;charset=UTF-8
X-Hudson: 1.395
X-Jenkins: 1.519
X-Jenkins-Session: 856997c2
X-Hudson-CLI-Port: 57801
X-Jenkins-CLI-Port: 57801
X-Jenkins-CLI2-Port: 57801
X-Instance-Identity: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhlCXIc6uKeJnpA9CrN4yn1VCxNIfxOdrZyRvc+PPWwgPUPwIBKaQNlfmJXxCtwRT3Op8SNWdjp+rGj1m+MiG4eDtzXgedm3g+0HJi1yh2V2wJj9ZhYrybCu6b899xd6zPoCoWRPZvwITxp0ngvVxlCYshq9Anjniygwi8KVbS0BG8KRgHsfVWZVPmLfXhkKS+LuA3o4Uhf2n6rQvdd3vliBkWrH4ovDgLbYnvbN8t0gSiQgEey7o6BaDVuxuVdB6fSstPGP1LxlSRxB5Vnn8/UI7rOnPV/251UP3RrD28mtx4k0eBtbyogTKR705mU8k8xwrcNh6uToHLE+j/ApnSQIDAQAB
X-SSH-Endpoint: myserver.com:57800
Content-Length: 7162
Connection: Keep-Alive
Date: Thu, 14 Nov 2013 00:25:42 GMT
X-Powered-By: Servlet/2.5 (Winstone/0.9.10)
Set-Cookie: JSESSIONID.91be6b77=88251c6f0bd5cff37e8dc5161c326a07; Path=/; HttpOnly
--response end--
200 OK
Registered socket 300 for persistent reuse.
Stored cookie myserver.com 8080 / <session> <insecure> [expiry none] JSESSIONID.91be6b77 88251c6f0bd5cff37e8dc5161c326a07
Length: 7162 (7.0K) [text/html]
Saving to: `build@token=1715b88bfba6717fadee72f5d5ecd17a'
100%[=============================================================================> ] 7,162 --.-K/s in 0.06s
2013-11-13 17:25:42 (111 KB/s) - `build@token=1715b88bfba6717fadee72f5d5ecd17a' saved [7162/7162]
============================ end of trace
The problem is not specific to using the CLI; a similar error is logged when trying to perform remote execution using an API token.