{"id":1598,"date":"2019-09-17T14:50:13","date_gmt":"2019-09-17T11:50:13","guid":{"rendered":"https:\/\/artem.services\/?p=1409"},"modified":"2020-03-02T17:02:57","modified_gmt":"2020-03-02T14:02:57","slug":"1598","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=1598&lang=en","title":{"rendered":"\u00a0Jenkins &#8212; Kubernetes plugin: An example of building an image with a Maven project"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"alignnone wp-image-819 size-full\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo.png\" alt=\"\" width=\"1280\" height=\"412\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo.png 1280w, https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo-300x97.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo-768x247.png 768w, https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo-1024x330.png 1024w, https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo-954x307.png 954w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>An example of a pipeline for working with the plugin for kubernetis. We build the maven project, create a docker image with the received artifact and push it into the docker image storage.<\/p>\n<p>&nbsp;<\/p>\n<h3>Pipeline:<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npodTemplate(\r\n  containers: [\r\n    containerTemplate(\r\n      name: 'maven',\r\n      image: 'maven:latest',\r\n      command: 'cat',\r\n      ttyEnabled: true),\r\n    containerTemplate(\r\n      name: 'docker',\r\n      image: 'docker:latest',\r\n      command: 'cat',\r\n      ttyEnabled: true,\r\n      envVars: [\r\n        secretEnvVar(key: 'DOCKER_LOGIN', secretName: 'docker-regestry-credentials', secretKey: 'username'),\r\n        secretEnvVar(key: 'DOCKER_PASSWORD', secretName: 'docker-regestry-credentials', secretKey: 'password'),\r\n        envVar(key: 'DOCKER_REGESTRY_URL', value: 'docker.artem.services'),\r\n        envVar(key: 'DOCKER_REPO', value: 'artem')\r\n      ]\r\n    )\r\n  ],\r\n  volumes: [\r\n    hostPathVolume(\r\n      hostPath: '\/var\/run\/docker.sock',\r\n      mountPath: '\/var\/run\/docker.sock')]\r\n)\r\n{\r\n  node(POD_LABEL) {\r\n    stage('Get a Maven project') {\r\n      git 'https:\/\/git.artem.services\/artem\/maven-project.git'\r\n      container('maven') {\r\n        stage('Build a Maven project') {\r\n          sh 'mvn -B clean install'\r\n        }\r\n      }\r\n    }\r\n\r\n    stage('Build Docker image') {\r\n      container('docker') {\r\n        writeFile file: &quot;Dockerfile&quot;, text: &quot;&quot;&quot;\r\n            FROM tomcat:jdk8\r\n            COPY .\/web\/target\/*.war \/usr\/local\/tomcat\/webapps\/\r\n        &quot;&quot;&quot;\r\n        sh &quot;docker build -t \\$DOCKER_REGESTRY_URL\/\\$DOCKER_REPO\/maven:${env.BUILD_ID} .&quot;\r\n        sh &quot;docker login -u \\$DOCKER_LOGIN -p \\$DOCKER_PASSWORD \\$DOCKER_REGESTRY_URL&quot;\r\n        sh &quot;docker push \\$DOCKER_REGESTRY_URL\/\\$DOCKER_REPO\/maven:${env.BUILD_ID}&quot;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<blockquote><p><strong>Dockerfile<\/strong> &#8212; already created in the pipeline itself.<br \/>\n<strong>envVar<\/strong> &#8212; taken from the secret of kubernetes<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; An example of a pipeline for working with the plugin for kubernetis. We build the maven project, create a docker image with the received artifact and push it into the docker image storage. &nbsp; Pipeline: &nbsp; Dockerfile &#8212; already created in the pipeline itself. envVar &#8212; taken from the secret of kubernetes<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[613],"tags":[617,551,641,1247,1249],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1598"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1598"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1598\/revisions"}],"predecessor-version":[{"id":1600,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1598\/revisions\/1600"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}