{"id":6452,"date":"2016-04-15T14:26:18","date_gmt":"2016-04-15T12:26:18","guid":{"rendered":"http:\/\/www.b.shuttle.de\/hayek\/hayek\/jochen\/wp\/blog-en\/?p=6452"},"modified":"2021-09-15T17:15:23","modified_gmt":"2021-09-15T15:15:23","slug":"jenkins-how-to-authenticate-as-a-scripted-client","status":"publish","type":"post","link":"https:\/\/wp.jochen.hayek.name\/blog-en\/2016\/04\/15\/jenkins-how-to-authenticate-as-a-scripted-client\/","title":{"rendered":"Jenkins: how to authenticate as a scripted client?"},"content":{"rendered":"<ul>\n<li><a href=\"https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Authenticating+scripted+clients\">https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Authenticating+scripted+clients<\/a><\/li>\n<\/ul>\n<blockquote><p>To make scripted clients (such as wget) invoke operations that require authorization (such as scheduling a build), use HTTP BASIC authentication to specify the user name and the API token. This is often more convenient than emulating the form-based authentication.<\/p><\/blockquote>\n<p>The article quote above mentions &#8220;<em>buildToken<\/em>&#8220;, but I don&#8217;t need it at all.<\/p>\n<p>The article quoted above has a section on <em>wget<\/em>. It recommends using &#8220;<code>--auth-no-challenge<\/code>&#8221; and also &#8220;<code>--secure-protocol=TLSv1<\/code>&#8220;, but a simple &#8220;<code>wget --http-user=<em>user<\/em> --http-password=<em>apiToken<\/em><\/code>&#8221; works for me. The article explains, where to find the user&#8217;s\u00a0<em>apiToken<\/em>\u00a0(\u2192 within the Jenkins user&#8217;s own configuration).<\/p>\n<p>I also successfully tried &#8220;<code>curl --user <em>user<\/em>:<em>apiToken<\/em><\/code>&#8220;. <em>wget<\/em>&#8216;s &#8220;<code>--auth-no-challenge<\/code>&#8221; corresponds to <em>curl<\/em>&#8216;s &#8220;<code>--basic<\/code>&#8220;. (But I will only apply them, once I am stuck w\/o them.)<\/p>\n<p>My Jenkins URLs\u00a0are usually actually &#8230;\/api\/xml ones, and I use <a href=\"https:\/\/en.wikipedia.org\/wiki\/XMLStarlet\">XMLStarlet<\/a> for the XPath-style extractions. My\u00a0command lines look like this:<\/p>\n<pre>$ wget --quiet --output-document - --http-user=<em>user<\/em> --http-password=<em>apiToken<\/em> ...\/api\/xml | xmlstartlet ...\n\n$ curl --silent --user <em>user<\/em>:<em>apiToken<\/em> ...\/api\/xml | xmlstartlet ...<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Authenticating+scripted+clients To make scripted clients (such as wget) invoke operations that require authorization (such as scheduling a build), use HTTP BASIC authentication to specify the user name and the API token. This is often more convenient than emulating the form-based authentication. The article quote above mentions &#8220;buildToken&#8220;, but I don&#8217;t need it at all. The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_share_on_mastodon":"0"},"categories":[851,732],"tags":[],"class_list":["post-6452","post","type-post","status-publish","format-standard","hentry","category-xmlstarlet","category-xpath"],"share_on_mastodon":{"url":"","error":""},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paO0kP-1G4","jetpack_likes_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/6452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/comments?post=6452"}],"version-history":[{"count":1,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/6452\/revisions"}],"predecessor-version":[{"id":11884,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/6452\/revisions\/11884"}],"wp:attachment":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/media?parent=6452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/categories?post=6452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/tags?post=6452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}