{"id":1944,"date":"2015-10-18T18:11:53","date_gmt":"2015-10-18T17:11:53","guid":{"rendered":"http:\/\/denbeke.be\/blog\/?p=1944"},"modified":"2016-04-04T20:21:06","modified_gmt":"2016-04-04T19:21:06","slug":"configuring-jenkins-on-ubuntu-for-c-gtest-and-bitbucket","status":"publish","type":"post","link":"https:\/\/denbeke.be\/blog\/servers\/configuring-jenkins-on-ubuntu-for-c-gtest-and-bitbucket\/","title":{"rendered":"Configuring Jenkins on Ubuntu (for C++, GTest and Bitbucket)"},"content":{"rendered":"<h3>\u00a0Installing<\/h3>\n<pre><code>wget -q -O - https:\/\/jenkins-ci.org\/debian\/jenkins-ci.org.key | sudo apt-key add -\r\nsudo sh -c 'echo deb http:\/\/pkg.jenkins-ci.org\/debian binary\/ &gt; \/etc\/apt\/sources.list.d\/jenkins.list'\r\nsudo apt-get update\r\n$ sudo apt-get install jenkins<\/code><\/pre>\n<p>Once installed, Jenkins will run at port <code>8080<\/code> on your server.<\/p>\n<ul>\n<li>Don&#8217;t forget to install a C\/C++ compiler<\/li>\n<li>Don&#8217;t forget to install dependencies like QT, libc++ and Boost<\/li>\n<\/ul>\n<h3 id=\"configuring\">Configuring<\/h3>\n<h4 id=\"security\">Security<\/h4>\n<p>Before doing anything else, you must secure your installation.<br \/>\nNavigate to <em>Jenkins<\/em>, <em>Manage Jenkins<\/em>, <em>Configure Global Security<\/em>.<\/p>\n<p>On this page you can specify all security settings. The most simple case is to use Jenkins\u2019 own user database.<br \/>\nIf you refresh the page after enabling this option, you will see a <em>Register<\/em> button in top right corner of the page. <strong>Create an account before proceeding.<\/strong><\/p>\n<p>Now you have an account, you can select <em>Matrix-based security<\/em>. This will show a list (matrix) of all security options. You can restrict the access for the anonymous user there.<br \/>\nYou should add your account to the security matrix with administrator access <strong>before<\/strong> saving. Otherwise you will lock yourself out!<br \/>\nYou can eventually add new users there with their own permissions.<\/p>\n<p><a href=\"http:\/\/denbeke.be\/blog\/servers\/configuring-jenkins-on-ubuntu-for-c-gtest-and-bitbucket\/attachment\/jenkins-global-security-matrix\/\" rel=\"attachment wp-att-1947\"><img loading=\"lazy\" class=\"size-full wp-image-1947 aligncenter\" src=\"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/10\/Jenkins-global-security-matrix.png\" alt=\"Jenkins global security matrix\" width=\"684\" height=\"492\" srcset=\"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/10\/Jenkins-global-security-matrix.png 684w, https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/10\/Jenkins-global-security-matrix-300x216.png 300w\" sizes=\"(max-width: 684px) 100vw, 684px\" \/><\/a><\/p>\n<p>If you lock yourself out, you can manually disable security in <code>\/var\/lib\/jenkins\/config.xml<\/code>.<br \/>\nChange <code>&lt;useSecurity&gt;true&lt;\/useSecurity&gt;<\/code> to <code>&lt;useSecurity&gt;false&lt;\/useSecurity&gt;<\/code> and restart Jenkins: <code>sudo service jenkins restart<\/code>.<\/p>\n<h4 id=\"adding-build-job\">Adding build job<\/h4>\n<p>On some Jenkins installations you must install the <a href=\"https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Git+Plugin\" target=\"_blank\">Git plugin<\/a> before you can use git as SCM.<\/p>\n<h5 id=\"ssh-keys\">SSH keys<\/h5>\n<p>We also need to configure SSH keys for Bitbucket so we don&#8217;t have to use plain text passwords.<\/p>\n<pre><code>$ ssh-keygen \r\nGenerating public\/private rsa key pair.\r\nEnter file in which to save the key (\/Users\/Mathias\/.ssh\/id_rsa): \r\n\/Users\/Mathias\/.ssh\/id_rsa already exists.\r\nEnter passphrase (empty for no passphrase): \r\nEnter same passphrase again: \r\npassphrase too short: have 3 bytes, need &gt; 4\r\nSaving the key failed: \/Users\/Mathias\/.ssh\/id_rsa.\r\nThe key fingerprint is:\r\n4c:72:6c:3a:7f:a6:45:80:92:e7:39:b7:73:7b:c6:51 Mathias@Mac-Pro-van-Mathias.local\r\nThe key's randomart image is:\r\n+--[ RSA 2048]----+\r\n|       . 0..E    |\r\n|      o.o...     |\r\n|      .+B. o.    |\r\n|       *+oo.+    |\r\n|      C So.=+    |\r\n|          o=.    |\r\n|         ..o     |\r\n|                 |\r\n|                 |\r\n+-----------------+\r\n<\/code><\/pre>\n<p>On Bitbucket go to Manage account, click SSH keys.<br \/>\nThe SSH Keys page displays. If you have any existing keys, those appear on this page.<br \/>\nBack in your terminal, copy the contents of your <strong>public<\/strong> key file.<\/p>\n<pre><code>$ cat ~\/.ssh\/id_rsa.pub\r\n<\/code><\/pre>\n<p>More information on working with SSH keys (and Bitbucket) can be found <a href=\"https:\/\/confluence.atlassian.com\/bitbucket\/set-up-ssh-for-git-728138079.html\" target=\"_blank\">here<\/a>.<\/p>\n<h5 id=\"add-credentials-to-jenkins\">Add credentials to Jenkins<\/h5>\n<p>Now we have generated keys for our Git authentication, we can add them to the credentials in Jenkins.<br \/>\nOn the built configuration screen select <em>SSH username with private key<\/em> for credentials.<\/p>\n<p>Select your username, and <em>Enter directly<\/em> for the private key.<br \/>\nAgain, you can get the key from the console, but this time we need the <strong>private<\/strong> key:<\/p>\n<pre><code>$ cat ~\/.ssh\/id_rsa\r\n-----BEGIN RSA PRIVATE KEY-----\r\nMIIEpQIBAAKCAQEAn7shTGtFO0K33vBLFARGuZuzvOR7vKvMvjSxcRe9XvMVsny3\r\n7qPXRoInAvJKjlKfDjavrw0bq2L6zJdVd0J6c8dKDHkfZWpkLjo+NQcmp7xAPYQT\r\nQvwwZXgUx+G4hQf4xylJXtIbOse6AE8752Uj+qm7AoGBALXPaRMExDDEZx16h2UF\r\n4ebdyfmfYeAn2wa6bKJZFlMED0QiVDs0ybceydipTRaA2wmwAfwwegZZPoCjUOjD\r\naRTO7V8QU0o772tvU\/EL91XW8x7sf68KCbJQyJfBhM5L9u425L8J+cTuWv9DfsIV\r\n...\r\ngfUkZpi1hBt4WpuVCipiVtPTAoGATF1qKYZSUBBwy9kr2MPG3jP3Rw7NQFs5lpRF\r\nnIcxg8h5DBczdc9W\/EjFtbUmVSKJqTWpoMUxvLdhRojIpHK1pHqOpWI\/NnIJfzSr\r\nXXlGg2GYv6S5G91zZlvMtrfmQLyByxYaq319mTv45z1Cw9X4jQ4sUGtb3CPOTzSQ\r\n4iLszlUCgYEAlAzj5oYQE7pTp3OqYy\/0Mqyxv1zTP+Cr96SRjT74fd79wIlYf5E2\r\nhPzuOnr\/lxTmt+fXaHwLs6OJjL3CkpXbk+bU0PObsJJTIuGUeAVyCUHTupygrez5\r\noTvY7LbBq5LKQSXP3BBTeGRFIQvbWHhC3hFtPXY6pJs8WdFyclLS0JU=\r\n-----END RSA PRIVATE KEY-----\r\n<\/code><\/pre>\n<p>You also need to specify the passphrase (if you set one before).<\/p>\n<p><a href=\"http:\/\/denbeke.be\/blog\/servers\/configuring-jenkins-on-ubuntu-for-c-gtest-and-bitbucket\/attachment\/jenkins-credentials-ssh-key-git\/\" rel=\"attachment wp-att-1951\"><img loading=\"lazy\" class=\"size-full wp-image-1951 aligncenter\" src=\"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/10\/Jenkins-Credentials-SSH-key-git.png\" alt=\"Jenkins Credentials SSH key git\" width=\"640\" height=\"484\" srcset=\"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/10\/Jenkins-Credentials-SSH-key-git.png 640w, https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/10\/Jenkins-Credentials-SSH-key-git-300x227.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<h5 id=\"configuring-build-triggers\">Configuring build triggers<\/h5>\n<p>Choose for <code>Trigger builds remotely<\/code> and specify a really random authentication token.<br \/>\nYou can for example generate a random token using OpenSSL: <code>$ openssl rand -base64 16<\/code>.<\/p>\n<p>You also need the API key from your Jenkins account. Go to your profile page and click on <em>Configure<\/em>. On the configuration page click on <em>Show API Token<\/em>.<\/p>\n<p>Finally you can add trigger on Bitbucket. Go the repository&#8217;s settings page, and navigate to <em>Services<\/em>. Add a new Jenkins service with the following details:<\/p>\n<ul>\n<li>Endpoint: Jenkins URL in the following format \u2014 <code>http:\/\/username:apitoken@your-jenkins-url.com\/<\/code><\/li>\n<li>Project name: the project name that you\u2019ve set in Jenkins<\/li>\n<li>Token: the authentication token of the project (that we generated earlier).<\/li>\n<\/ul>\n<p><a href=\"http:\/\/denbeke.be\/blog\/servers\/configuring-jenkins-on-ubuntu-for-c-gtest-and-bitbucket\/attachment\/schermafbeelding-2015-10-18-om-19-06-31\/\" rel=\"attachment wp-att-1946\"><img loading=\"lazy\" class=\"size-full wp-image-1946 aligncenter\" src=\"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/10\/Schermafbeelding-2015-10-18-om-19.06.31.png\" alt=\"Schermafbeelding 2015-10-18 om 19.06.31\" width=\"484\" height=\"334\" srcset=\"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/10\/Schermafbeelding-2015-10-18-om-19.06.31.png 484w, https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/10\/Schermafbeelding-2015-10-18-om-19.06.31-300x207.png 300w\" sizes=\"(max-width: 484px) 100vw, 484px\" \/><\/a><\/p>\n<p>If you now do a push to your Bitbucket remote repo, it will automatically trigger a Jenkins build.<\/p>\n<h5 id=\"configuring-build\">Configuring build<\/h5>\n<p>If you want to build the project with CMake, you might have to install the <a href=\"https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/cmakebuilder+Plugin\" target=\"_blank\">CMake plugin<\/a> (and you need CMake on your server).<br \/>\nMaybe you also need the Build <a href=\"https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Build+Environment+Plugin\" target=\"_blank\">Environment plugin<\/a>.<\/p>\n<p>Once installed, you click on <em>Add build step<\/em> and you choose <em>CMake Build<\/em>. You can also specify a <em>Shell invocation<\/em> if you want to use your own make file or build commands.<\/p>\n<p>I won&#8217;t dig deeper into specific build settings, since that&#8217;s irrelevant for you particular project&#8230;<\/p>\n<h5 id=\"configuring-unit-test-gtest\">Configuring unit test (gtest)<\/h5>\n<p>If you use <a href=\"https:\/\/code.google.com\/p\/googletest\/\" target=\"_blank\">GoogleTest<\/a>, you can create a test output report with Jenkins. Execute gTest with this flag: <code>--gtest_output=xml:gtestresults.xml<\/code>.<\/p>\n<p>You also need to replace <code>notun<\/code> by <code>skipped<\/code> since Jenkins doesn&#8217;t like the first one.<\/p>\n<pre><code>awk '{ if ($1 == \"&lt;testcase\" &amp;&amp; match($0, \"notrun\")) print substr($0,0,length($0)-2) \"&gt;&lt;skipped\/&gt;&lt;\/testcase&gt;\"; else print $0;}' gtestresults.xml &gt; gtestresults-skipped.xml\r\nmv gtestresults.xml gtestresults.off\r\n<\/code><\/pre>\n<p>Now you have the xml report file, you must add the <em>Publish JUnit test result report<\/em> Post-build action with the <code>gtestresults-skipped.xml<\/code> file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0Installing wget -q -O &#8211; https:\/\/jenkins-ci.org\/debian\/jenkins-ci.org.key | sudo apt-key add &#8211; sudo sh -c &#8216;echo deb http:\/\/pkg.jenkins-ci.org\/debian binary\/ &gt; \/etc\/apt\/sources.list.d\/jenkins.list&#8217; sudo apt-get update $ sudo apt-get install jenkins Once installed, Jenkins will run at port 8080 on your server. Don&#8217;t forget to install a C\/C++ compiler Don&#8217;t forget to install dependencies like QT, libc++ and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[235,227],"tags":[204,203,263,253,212,228],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.6.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Configuring Jenkins on Ubuntu (for C++, GTest and Bitbucket) &ndash; DenBeke<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/denbeke.be\/blog\/servers\/configuring-jenkins-on-ubuntu-for-c-gtest-and-bitbucket\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Configuring Jenkins on Ubuntu (for C++, GTest and Bitbucket) &ndash; DenBeke\" \/>\n<meta property=\"og:description\" content=\"\u00a0Installing wget -q -O - https:\/\/jenkins-ci.org\/debian\/jenkins-ci.org.key | sudo apt-key add - sudo sh -c &#039;echo deb http:\/\/pkg.jenkins-ci.org\/debian binary\/ &gt; \/etc\/apt\/sources.list.d\/jenkins.list&#039; sudo apt-get update $ sudo apt-get install jenkins Once installed, Jenkins will run at port 8080 on your server. Don&#8217;t forget to install a C\/C++ compiler Don&#8217;t forget to install dependencies like QT, libc++ and [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/denbeke.be\/blog\/servers\/configuring-jenkins-on-ubuntu-for-c-gtest-and-bitbucket\/\" \/>\n<meta property=\"og:site_name\" content=\"DenBeke\" \/>\n<meta property=\"article:published_time\" content=\"2015-10-18T17:11:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-04-04T19:21:06+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/10\/Jenkins-global-security-matrix.png\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<meta name=\"twitter:creator\" content=\"@MthsBk\" \/>\n<meta name=\"twitter:site\" content=\"@MthsBk\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"5 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/denbeke.be\/blog\/#website\",\"url\":\"https:\/\/denbeke.be\/blog\/\",\"name\":\"DenBeke\",\"description\":\"Mathias Beke\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/denbeke.be\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/denbeke.be\/blog\/servers\/configuring-jenkins-on-ubuntu-for-c-gtest-and-bitbucket\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/10\/Jenkins-global-security-matrix.png\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/denbeke.be\/blog\/servers\/configuring-jenkins-on-ubuntu-for-c-gtest-and-bitbucket\/#webpage\",\"url\":\"https:\/\/denbeke.be\/blog\/servers\/configuring-jenkins-on-ubuntu-for-c-gtest-and-bitbucket\/\",\"name\":\"Configuring Jenkins on Ubuntu (for C++, GTest and Bitbucket) &ndash; DenBeke\",\"isPartOf\":{\"@id\":\"https:\/\/denbeke.be\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/denbeke.be\/blog\/servers\/configuring-jenkins-on-ubuntu-for-c-gtest-and-bitbucket\/#primaryimage\"},\"datePublished\":\"2015-10-18T17:11:53+00:00\",\"dateModified\":\"2016-04-04T19:21:06+00:00\",\"author\":{\"@id\":\"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/denbeke.be\/blog\/servers\/configuring-jenkins-on-ubuntu-for-c-gtest-and-bitbucket\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc\",\"name\":\"Mathias Beke\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/denbeke.be\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/015ba35e6ce4f5859e3888ca99807575?s=96&d=mm&r=g\",\"caption\":\"Mathias Beke\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1944"}],"collection":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/comments?post=1944"}],"version-history":[{"count":11,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1944\/revisions"}],"predecessor-version":[{"id":2097,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1944\/revisions\/2097"}],"wp:attachment":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/media?parent=1944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/categories?post=1944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/tags?post=1944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}