当尝试从任何REST客户端触发Jenkins作业时,我得到以下错误
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>
使用curl从终端
触发请求我使用以下语法
http://user: apiToken@jenkins.yourcompany.com/job/your_job/build ?令牌=令牌(参考:https://wiki.jenkins-ci.org/display/JENKINS/Authenticating +的+客户)
ie。curl -X POST http://user:apiToken@jenkins.yourcompany.com/job/your_job/build?token=TOKEN
选中" this build is parameterized ",从下拉菜单中选择凭据参数。使用
curl -X POST http://jenkins.rtcamp.com/job/Snapbox/buildWithParameters --user "username:password"
它解决了我的认证问题。
我的开发团队的配置设置是matrix-based security
,所以我必须找到我的组并给我的组工作空间访问权。
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
然后 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
For me
https://user: password@jenkins.mycompany.org/job/job_name/build ?令牌= my_token
在https://jenkins.mycompany.org/configureSecurity禁用CORS
希望对您有所帮助
尝试使用-u参数指定凭据:
curl -u user:apiToken -X POST http://jenkins.yourcompany.com/job/your_job/build?token=TOKEN
我提供了头授权参数value:BASIC base_64encoded(用户名:密码),运行正常
Authorization Basic bmltbWljdjpqZX*********
在全局安全选项中禁用"CSRF保护",因为这些url不发送post数据标识。
焦点:用户名:password@
curl -u user:apiToken -X POST http://username:password@jenkins.yourcompany.com/job/your_job/build?key1=value1&key2=value2 ...
如果您在ruby中使用jenkins api客户端遇到此问题。我认为詹金斯是阻止所有的get请求,而不是使用api_post_request。此外,您必须生成api令牌,因为普通密码不再工作。
@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
如果想要原始响应,可以将参数设置为true。默认参数或传递false将只返回响应代码。
还要确保构造正确的前缀。