{"id":5682,"date":"2015-10-28T11:14:59","date_gmt":"2015-10-28T10:14:59","guid":{"rendered":"http:\/\/www.b.shuttle.de\/hayek\/hayek\/jochen\/wp\/blog-en\/?p=5682"},"modified":"2015-10-28T11:14:59","modified_gmt":"2015-10-28T10:14:59","slug":"jenkins-env-win-compile","status":"publish","type":"post","link":"https:\/\/wp.jochen.hayek.name\/blog-en\/2015\/10\/28\/jenkins-env-win-compile\/","title":{"rendered":"Jenkins: setting up a the environment for a Windows\/Microsoft compilation job"},"content":{"rendered":"<ul>\n<li><a href=\"https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/EnvInject+Plugin\">https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/EnvInject+Plugin<\/a><\/li>\n<li><a href=\"https:\/\/www.gnu.org\/software\/make\/manual\/html_node\/Errors.html\">https:\/\/www.gnu.org\/software\/make\/manual\/html_node\/Errors.html<\/a>\u00a0&#8212; make&#8217;s exit code checking<\/li>\n<\/ul>\n<p>There are a couple of different ways of injecting environment variables:<\/p>\n<p>Within the &#8220;<em>Build Environment<\/em>&#8221; \/ &#8220;<em>Inject environment variables to the build process<\/em>&#8221; section of a Jenkins job (provided by the EnvInject plugin) you may me tempted to make use of a file named by &#8220;<em>Properties File Path<\/em>&#8221; that adds settings to your environment variables, e.g. &#8220;<em>c:jenkins-slaveslave-env.txt<\/em>&#8220;.<\/p>\n<p>As opposed to properties injection through such file using\u00a0a section &#8220;<em>Properties Content<\/em>&#8221; makes your environment set up more obvious and transparent. If you have a lot of jobs with an identical subset of properties, it certainly makes sense to have them within such a shared file. But there are also situations you can neither handle through &#8220;<em>Properties File Path<\/em>&#8221; nor through &#8220;<em>Properties Content<\/em>&#8220;:<\/p>\n<p>For using Microsoft Visual Studio&#8217;s C compiler on the command line you ought to call their <em>vcvarsall.bat<\/em>. Do not try to set up your compilation environment (<em>INCLUDE<\/em>, <em>Path<\/em>, <em>LIB<\/em>, <em>LIBPATH<\/em>, <em>SDK<\/em>, &#8230;) yourself! You can neither\u00a0use &#8220;Script File Path&#8221; nor &#8220;Script Content&#8221; for that, because &#8220;adding or overriding environment variables in the script doesn&#8217;t have any impacts in the build job&#8221;.<\/p>\n<p>This is what I suggest: <span style=\"text-decoration: underline\">Prepare<\/span> the call of <em>vcvarsall.bat<\/em> <span style=\"text-decoration: underline\">within<\/span> the section &#8220;<em>Build Environment<\/em>&#8221; \/ &#8220;<em>Properties Content<\/em>&#8221; instead.<\/p>\n<pre>PF=C:Program Files\nPFx86=C:Program Files (x86)\nVSINSTALLDIR=%PFx86%Microsoft Visual Studio 10.0\nVCINSTALLDIR=%VSINSTALLDIR%VC\nJAVA_HOME=$PFJavajdk1.8.0_60\nPath=$Path;%JAVA_HOME%bin<\/pre>\n<p>Within the section &#8220;<em>Build<\/em>&#8221; \/ &#8220;<em>Execute Windows batch command<\/em>&#8221; <span style=\"text-decoration: underline\">call<\/span> <em>vcvarsall.bat<\/em>:<\/p>\n<pre>call \"%VCINSTALLDIR%vcvarsall.bat\"<\/pre>\n<p>Variables set up through <em>vcvarsall.bat<\/em> that you may want to make use of:<\/p>\n<ul>\n<li><em>WindowsSdkDir=&#8230;Microsoft SDKsWindows&#8230;<\/em><\/li>\n<li>&#8230;<\/li>\n<\/ul>\n<p>If you want to call <em>ant<\/em> as a <span style=\"text-decoration: underline\">separate<\/span> build step (&#8220;<em>Add build step<\/em>&#8220;), this is not going to work, as the environment set up through <em>vcvarsall.bat<\/em> is <span style=\"text-decoration: underline\">not available within that separate build step<\/span>. That&#8217;s unfortunate, but that&#8217;s the way it is. You rather want to call <em>ant<\/em> explicitly within the same Windows <em>batch<\/em>:<\/p>\n<pre>call \"%VCINSTALLDIR%vcvarsall.bat\"\n\ncd src || exit 1\n\"%PF%apache-ant-1.9.6binant.bat\" -file build.xml &amp;&amp; exit %%ERRORLEVEL%%\n<\/pre>\n<p>Good old <em>make<\/em> checked each action line&#8217;s exit code, and if an action had a non-zero exit code, <em>make<\/em> stopped and told you why it stopped. You could circumvent that globally through the command line option &#8220;<em>-i<\/em>&#8220;, you could circumvent that locally through an action line prefix: &#8220;<em>&#8211;<\/em>&#8220;.<\/p>\n<p>Windows batch jobs (within a Jenkins job) do not run within a framework like that. You have to check exit codes yourself, add &#8220;<em>|| exit 1<\/em>&#8221; wherever appropriate. If you don&#8217;t, certain problems do not get recognised.\t\t\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/EnvInject+Plugin https:\/\/www.gnu.org\/software\/make\/manual\/html_node\/Errors.html\u00a0&#8212; make&#8217;s exit code checking There are a couple of different ways of injecting environment variables: Within the &#8220;Build Environment&#8221; \/ &#8220;Inject environment variables to the build process&#8221; section of a Jenkins job (provided by the EnvInject plugin) you may me tempted to make use of a file named by &#8220;Properties File Path&#8221; that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_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},"jetpack_post_was_ever_published":false,"_share_on_mastodon":"0"},"categories":[666],"tags":[],"class_list":["post-5682","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"share_on_mastodon":{"url":"","error":""},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paO0kP-1tE","jetpack_likes_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/5682","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=5682"}],"version-history":[{"count":0,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/5682\/revisions"}],"wp:attachment":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/media?parent=5682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/categories?post=5682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/tags?post=5682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}