{"id":1065,"date":"2019-04-25T16:42:25","date_gmt":"2019-04-25T13:42:25","guid":{"rendered":"https:\/\/artem.services\/?p=1053"},"modified":"2020-03-24T17:51:19","modified_gmt":"2020-03-24T14:51:19","slug":"jenkins-d0-bd-d0-b0-d0-b3-d1-80-d1-83-d0-b7-d0-be-d1-87-d0-bd-d0-be-d0-b5-d1-82-d0-b5-d1-81-d1-82-d0-b8-d1-80-d0-be-d0-b2-d0-b0-d0-bd-d0-b8-d0-b5-jmeterantslack","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=1065&lang=en","title":{"rendered":"Jenkins &#8212; Perfomance testing (JMeter + Ant + Slack)"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-819\" 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><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">On the server with <strong>Jenkins<\/strong> download<\/span><\/span> <a href=\"https:\/\/jmeter.apache.org\/download_jmeter.cgi\" target=\"_blank\" rel=\"noopener noreferrer\">JMeter<\/a><\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Also need<\/span><\/span> <a href=\"https:\/\/jmeter-plugins.org\/?search=jpgc-cmd\" target=\"_blank\" rel=\"noopener noreferrer\">JMeterPluginsCMD<\/a><\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Create a directory for storage:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmkdir -p \/var\/lib\/jmeter\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Download and unzip the contents of two archives to this directory.<\/span><\/span><\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">So that the structure is as follows:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@jenkins:~# ll \/var\/lib\/jmeter\/\r\ntotal 64K\r\ndrwxr-xr-x  8 jenkins jenkins 4.0K Apr 24 15:39 .\r\ndrwxr-xr-x 37 root    root    4.0K Mar 22 10:29 ..\r\ndrwxr-xr-x  5 jenkins jenkins 4.0K Apr 24 17:47 bin\r\ndrwxr-xr-x  5 jenkins jenkins 4.0K Mar 10 08:41 docs\r\ndrwxr-xr-x  2 jenkins jenkins 4.0K Mar 10 08:43 extras\r\ndrwxr-xr-x  4 jenkins jenkins 4.0K Apr 24 17:47 lib\r\n-rw-r--r--  1 jenkins jenkins  15K Mar 10 10:08 LICENSE\r\ndrwxr-xr-x  4 jenkins jenkins 4.0K Mar 10 10:08 licenses\r\n-rw-r--r--  1 jenkins jenkins  172 Mar 10 10:08 NOTICE\r\ndrwxr-xr-x  6 jenkins jenkins 4.0K Mar 10 09:58 printable_docs\r\n-rw-r--r--  1 jenkins jenkins  10K Mar 10 10:08 README.md\r\n<\/pre>\n<p><!--more--><\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">We create a repository with the following <a href=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/04\/Jenkins-JMeter.zip\">contents<\/a>.<\/span><\/span><\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">We create an Item for <strong>Multibranch Pipeline<\/strong> in <strong>Jenkins<\/strong>.<\/span><\/span><\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Content of <strong>Jenkinsfile<\/strong>:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npipeline {\r\n    agent any\r\n    parameters {\r\n        string(name: 'SERVER_URL', defaultValue: 'example.org', description: 'URL for load test')\r\n        string(name: 'SITE_PATH', defaultValue: '\/', description: 'Path for URL. Default - &quot;\/&quot;')\r\n        string(name: 'NUMBER_OF_THREADS', defaultValue: '10', description: 'Number of Threads (Users). Default - 10')\r\n        string(name: 'RAMP_TIME', defaultValue: '5', description: 'Ramp-Up Period. Default - 5(sec)')\r\n        string(name: 'DURATION_TIME', defaultValue: '5', description: 'Duration (seconds). Default - 5')\r\n        string(name: 'STARTUP_DELAY', defaultValue: '5', description: 'Startup delay (seconds). Default - 5')\r\n        booleanParam(name: 'DELETE_CACHE', defaultValue: false, description: 'Toggle this value to build with cache clearing.')\r\n    }\r\n    options {\r\n        ansiColor('xterm')\r\n        timeout(time: 30, unit:'MINUTES')\r\n        timestamps()\r\n    }\r\n    environment {\r\n        def ANT = '\/usr\/bin\/ant'\r\n        def JMETER = '\/var\/lib\/jmeter\/bin\/jmeter'\r\n        def JMETER_HOME = '\/var\/lib\/jmeter\/'\r\n        def TEMPLATE = 'SITE_SIMPLE.jmx'\r\n        \/\/ Perository\r\n        def GIT_REPO = 'https:\/\/git.artem.services\/scm\/dev\/jenkins-jmeter.git'\r\n        def GIT_CRED = 'svc-bitbucket'\r\n        \/\/ Slack\r\n        def SLACK_CHANNEL_ID = credentials('artem-slack-channel-id-debug')\r\n        def SLACK_TOKEN = credentials('artem-slack-token')\r\n        def GIF_SUCCESS = giphySearchRandomByKeyword(credentialsId: 'giphy-api-key', keyword: &quot;hacker&quot;, rating: 'g', imageSize: 'downsized_medium')\r\n    }\r\n    stages {\r\n        stage ('Delete work dir') {\r\n            when { expression { return params.DELETE_CACHE } }\r\n            steps {\r\n                deleteDir()\r\n                git branch: &quot;${BRANCH_NAME}&quot;, credentialsId: &quot;${GIT_CRED}&quot;, url: &quot;${GIT_REPO}&quot;\r\n            }\r\n        }      \r\n        stage ('Configure template') {\r\n            when { branch 'master' }\r\n            steps {\r\n                sh 'envsubst &lt; &quot;ant\/templates\/\\&quot;${TEMPLATE}\\&quot;&quot; &gt; &quot;ant\/templates\/\\&quot;${TEMPLATE}\\&quot;.tmp&quot;'\r\n                sh 'envsubst &lt; &quot;ant\/build\/build.properties&quot; &gt; &quot;ant\/build.properties&quot;'\r\n            }\r\n        }\r\n        stage ('Load test') {\r\n            when { branch 'master' }\r\n            steps {\r\n                sh &quot;cd ant &amp;&amp; ${ANT} clean&quot;\r\n                sh &quot;cd ant &amp;&amp; ${ANT} run&quot;\r\n                sh &quot;cd ant &amp;&amp; ${ANT} generate-report&quot;\r\n                sh &quot;cd ant &amp;&amp; ${ANT} generate-chart&quot;\r\n                sh &quot;wget ${GIF_SUCCESS} -O ant\/result\/success.gif&quot;\r\n            }\r\n        }\r\n    } \r\n    post {\r\n        always {\r\n            sh &quot;rm ant\/templates\/${TEMPLATE}.tmp | true&quot;\r\n            sh &quot;rm ant\/build.properties | true&quot;\r\n        }\r\n        success {\r\n            slackSend channel: &quot;${SLACK_CHANNEL_ID}&quot;, color: 'good', message: &quot;Perfomance test domain: `\\&quot;${SERVER_URL}\\&quot;` was successful.&quot;\r\n            script {\r\n                sh &quot;chmod +x .\/upload_images.sh&quot;\r\n                sh &quot;.\/upload_images.sh ${SLACK_CHANNEL_ID} ${SLACK_TOKEN}&quot;\r\n            }\r\n        }\r\n        failure {\r\n            slackSend channel: &quot;${SLACK_CHANNEL_ID}&quot;, color: 'danger', message: &quot;Perfomance test domain: `\\&quot;${SERVER_URL}\\&quot;` was finished with some error. Watch the Jenkins Console Output: ${JOB_URL}${BUILD_ID}\/consoleFull&quot;\r\n        }\r\n    }\r\n}\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span title=\"\">Item performs load testing, generates a report and png graphics, and sends the graphics to the <strong>Slack<\/strong> channel.<\/span> <span class=\"\" title=\"\">In this <strong>Item<\/strong>, <strong>Giphy Plugin<\/strong> is used, either connect it, or delete its lines from &quot;<strong>Jenkinsfile<\/strong>&quot; and &quot;<strong>upload_images.sh<\/strong>&quot;<\/span><\/span><\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">For the &quot;<strong>ant generate-chart<\/strong>&quot; command, additional plugins may be required, to do this, go to the directory with the repository contents and<\/span> <span class=\"\" title=\"\">execute the command:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nant install-plugins\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Test result:<\/span><\/span><\/p>\n<p><img loading=\"lazy\" class=\"size-full wp-image-1059 aligncenter\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/04\/Screen-Shot-2019-04-25-at-6.29.52-PM.png\" alt=\"\" width=\"978\" height=\"1252\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/04\/Screen-Shot-2019-04-25-at-6.29.52-PM.png 978w, https:\/\/artem.services\/wp-content\/uploads\/2019\/04\/Screen-Shot-2019-04-25-at-6.29.52-PM-234x300.png 234w, https:\/\/artem.services\/wp-content\/uploads\/2019\/04\/Screen-Shot-2019-04-25-at-6.29.52-PM-768x983.png 768w, https:\/\/artem.services\/wp-content\/uploads\/2019\/04\/Screen-Shot-2019-04-25-at-6.29.52-PM-800x1024.png 800w, https:\/\/artem.services\/wp-content\/uploads\/2019\/04\/Screen-Shot-2019-04-25-at-6.29.52-PM-954x1221.png 954w\" sizes=\"(max-width: 978px) 100vw, 978px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>On the server with Jenkins download JMeter Also need JMeterPluginsCMD Create a directory for storage: Download and unzip the contents of two archives to this directory. So that the structure is as follows:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[613],"tags":[799,615,617,801,491],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1065"}],"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=1065"}],"version-history":[{"count":3,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1065\/revisions"}],"predecessor-version":[{"id":1755,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1065\/revisions\/1755"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}