29

I am getting the following error while trying to trigger Jenkins job from any REST Client

Authentication required

     <!-- You are authenticated as: anonymous
Groups that you are in:

Permission you need to have (but didn't):
hudson.model.Hudson.Read
... which is implied by: hudson.security.Permission.GenericRead
... which is implied by: hudson.model.Hudson.Administer
-->
    </body> </html>

The request is getting triggered while using curl from terminal

I am using the following syntax

http://user:apiToken@jenkins.yourcompany.com/job/your_job/build?token=TOKEN [ref :https://wiki.jenkins-ci.org/display/JENKINS/Authenticating+scripted+clients]

ie. curl -X POST http://user:apiToken@jenkins.yourcompany.com/job/your_job/build?token=TOKEN

Mike Caron
  • 14,351
  • 4
  • 49
  • 77
nnc
  • 790
  • 2
  • 14
  • 31
  • I'm using the same scheme and it's working for me in the browser: user:ApiToken@domain.com/job/my_job/build?token=TOKEN – Anoyz Feb 01 '17 at 16:12

8 Answers8

12

Check this "This build is parameterized " , select the credentials parameter from drop down. Use this

curl -X POST http://jenkins.rtcamp.com/job/Snapbox/buildWithParameters --user "username:password"

It solved my authentication problem.

I hope it will help others too.

Juhi Saxena
  • 1,197
  • 11
  • 17
6

My development team's configuration settings were matrix-based security so I had to find my group and give my group workspace access.

1.Click on Manage Jenkins .   
2.Click on Configure Global Security .  
3.in matrix-based security change: 

Overall - Read   
Job - Build  
Job - Read   
Job - Workspace  

Then

    POST jobUrl/buildWithParameters HTTP/1.1
    Host: user:token
    Authorization: Basic dWdlbmxpazo4elhjdmJuTQ==
    Cache-Control: no-cache
    Content-Type: application/x-www-form-urlencoded

    Branch=develop
SpaceDust__
  • 4,844
  • 4
  • 43
  • 82
2

Try using the -u parameter to specify the credentials:

curl -u user:apiToken -X POST http://jenkins.yourcompany.com/job/your_job/build?token=TOKEN

gareth_bowles
  • 20,760
  • 5
  • 52
  • 82
  • This does work with curl. But I am trying to trigger the same job from POSTMAN REST client and it fails with authentication required. – nnc Aug 19 '14 at 23:21
  • If it works with curl you're obviously having a specific problem with the postman client parameters. Sorry that I don't know anything about that, but at least it narrows down the problem. – gareth_bowles Aug 20 '14 at 18:57
2

I provided header Authorization parameter with value : BASIC base_64encoded(username:password) and it worked fine.

Authorization Basic bmltbWljdjpqZX*********

nnc
  • 790
  • 2
  • 14
  • 31
  • worked for me too. if you need a Base64 encoder, check https://www.base64encode.org/ – felipecao Apr 17 '15 at 12:07
  • 2
    I'd strongly recommend against using a base64encode.org for your credentials because it sends its input to the server. Many systems will have a base64 command that you can use like `echo -n 'test:testpass' | base64` – econerd4ever Feb 01 '17 at 18:10
1

Simply disable "CSRF Protection" in the global Security Options, because those URLs don't send post data identification.

Dave Dundee
  • 101
  • 3
0

focal point : username:password@

curl -u user:apiToken -X POST http://username:password@jenkins.yourcompany.com/job/your_job/build?key1=value1&key2=value2 ...
Demon
  • 1
  • 1
0

If you are encountering this problem with jenkins api client in ruby. I figured Jenkins is blocking all the get request, instead use api_post_request. Also, you have to generate api token because normal password is not working anymore.

@client = JenkinsApi::Client.new(
    server_url: "",
    username: '',
    password: ""
)
SITE_FILE_PATH = 'artifact/target/site'.freeze
@jenkins_uri=''
@jenkins_job_name=''

def latest_test_file_path
    "/job/#{@jenkins_job_name}/job/master/lastSuccessfulBuild/#{SITE_FILE_PATH}/Test-Results/test-results.html"
end

puts @client.api_post_request(latest_test_file_path,{},true).body

you can set the parameter true if you want the raw response. default parameter or passing false will just return response code.

Also make sure to construct the right prefix. You can refer to the above snipped.

C-mmon
  • 43
  • 7