{"id":2264,"date":"2021-06-23T19:11:59","date_gmt":"2021-06-23T16:11:59","guid":{"rendered":"https:\/\/artem.services\/?p=2177"},"modified":"2022-06-08T20:58:54","modified_gmt":"2022-06-08T17:58:54","slug":"2264","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=2264&lang=en","title":{"rendered":"\u00a0Jenkins &#8212; Python VirtualEnv with version selection"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"aligncenter 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>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">To select a Python version in the pipeline, you need to have the required versions installed on the system.<\/span><\/span><\/span><\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Further actions were performed on <strong>CentOS 7<\/strong> and the installation of binaries took place in the &quot;<strong>\/usr\/bin\/<\/strong>&quot; directory for convenience, since the system already has versions &quot;<strong>2.7<\/strong>&quot; and &quot;<strong>3.6<\/strong>&quot; installed from the repository along this path.<\/span><\/span><\/span><\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Install dependencies:<\/span><\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nyum install gcc openssl-devel bzip2-devel libffi-devel wget\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Download the necessary sources of the necessary versions, in this case: &quot;<strong>3.7<\/strong>&quot;, &quot;<strong>3.8<\/strong>&quot; and &quot;<strong>3.9<\/strong>&quot;<\/span><\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncd \/usr\/src\r\n\r\nwget https:\/\/www.python.org\/ftp\/python\/3.7.9\/Python-3.7.9.tgz\r\nwget https:\/\/www.python.org\/ftp\/python\/3.8.9\/Python-3.8.9.tgz\r\nwget https:\/\/www.python.org\/ftp\/python\/3.9.5\/Python-3.9.5.tgz\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Unzip:<\/span><\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ntar xzf Python-3.7.9.tgz\r\ntar xzf Python-3.8.9.tgz\r\ntar xzf Python-3.9.5.tgz\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Install:<\/span><\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncd Python-3.7.9\r\n.\/configure --enable-optimizations --prefix=\/usr\r\nmake altinstall\r\n\r\ncd ..\/Python-3.8.9\r\n.\/configure --enable-optimizations --prefix=\/usr\r\nmake altinstall\r\n\r\ncd ..\/Python-3.9.5\r\n.\/configure --enable-optimizations --prefix=\/usr\r\nmake altinstall\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Now let&#8217;s install the plugin<\/span><\/span><\/span> <a href=\"https:\/\/plugins.jenkins.io\/pyenv-pipeline\/\" target=\"_blank\" rel=\"noopener noreferrer\">Pyenv Pipeline<\/a><\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Go to <strong>Jenkins<\/strong> settings<\/span><\/span><\/span><\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1782\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2020\/03\/001.png\" alt=\"\" width=\"349\" height=\"383\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2020\/03\/001.png 349w, https:\/\/artem.services\/wp-content\/uploads\/2020\/03\/001-273x300.png 273w\" sizes=\"(max-width: 349px) 100vw, 349px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Section &quot;<strong>Manage Plugins<\/strong>&quot;<\/span><\/span><\/span><\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1783\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2020\/03\/002.png\" alt=\"\" width=\"927\" height=\"493\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2020\/03\/002.png 927w, https:\/\/artem.services\/wp-content\/uploads\/2020\/03\/002-300x160.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2020\/03\/002-768x408.png 768w\" sizes=\"(max-width: 927px) 100vw, 927px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Go to the &quot;<strong>Available<\/strong>&quot; tab and in the search we specify &quot;<strong>Pyenv Pipeline<\/strong>&quot;<\/span><\/span><\/span><\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-2178\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.20.45.png\" alt=\"\" width=\"1398\" height=\"160\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.20.45.png 1398w, https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.20.45-300x34.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.20.45-1024x117.png 1024w, https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.20.45-768x88.png 768w, https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.20.45-954x109.png 954w, https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.20.45-1354x155.png 1354w\" sizes=\"(max-width: 1398px) 100vw, 1398px\" \/><\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">And install it.<\/span><\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">To select the version, we will use the &quot;<strong>choice<\/strong>&quot; parameter<\/span><\/span><\/span><\/p>\n<h3>Pipeline:<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nproperties([\r\n  parameters([\r\n    choice(\r\n      name: &#039;PYTHON&#039;,\r\n      description: &#039;Choose Python version&#039;,\r\n      choices: [&quot;python2.7&quot;, &quot;python3.6&quot;, &quot;python3.7&quot;, &quot;python3.8&quot;, &quot;python3.9&quot;].join(&quot;\\n&quot;)\r\n    ),\r\n    base64File(\r\n      name: &#039;REQUIREMENTS_FILE&#039;,\r\n      description: &#039;Upload requirements file (Optional)&#039;\r\n    )\r\n  ])\r\n])\r\n\r\npipeline {\r\n  agent any\r\n  options {\r\n    buildDiscarder(logRotator(numToKeepStr: &#039;5&#039;))\r\n    timeout(time: 60, unit:&#039;MINUTES&#039;)\r\n    timestamps()\r\n  }\r\n  stages {\r\n    stage(&quot;Python&quot;){\r\n      steps{\r\n        withPythonEnv(&quot;\/usr\/bin\/${params.PYTHON}&quot;) {\r\n          script {\r\n            if ( env.REQUIREMENTS_FILE.isEmpty() ) {\r\n              sh &quot;python --version&quot;\r\n              sh &quot;pip --version&quot;\r\n              sh &quot;echo Requirements file not set. Run Python without requirements file.&quot;\r\n            }\r\n            else {\r\n              sh &quot;python --version&quot;\r\n              sh &quot;pip --version&quot;\r\n              sh &quot;echo Requirements file found. Run PIP install using requirements file.&quot;\r\n              withFileParameter(&#039;REQUIREMENTS_FILE&#039;) {\r\n                sh &#039;cat $REQUIREMENTS_FILE &gt; requirements.txt&#039;\r\n              }\r\n              sh &quot;pip install -r requirements.txt&quot;\r\n            }\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Let&#8217;s start the build:<\/span><\/span><\/span><\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-2179\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.48.39.png\" alt=\"\" width=\"690\" height=\"636\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.48.39.png 690w, https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.48.39-300x277.png 300w\" sizes=\"(max-width: 690px) 100vw, 690px\" \/><\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Select the desired version, for example, &quot;<strong>3.9<\/strong>&quot; and run the build:<\/span><\/span><\/span><\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-2180\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.48.51.png\" alt=\"\" width=\"628\" height=\"640\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.48.51.png 628w, https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.48.51-294x300.png 294w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Let&#8217;s check the build log:<\/span><\/span><\/span><\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-2181\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.49.41.png\" alt=\"\" width=\"2110\" height=\"722\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.49.41.png 2110w, https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.49.41-300x103.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.49.41-1024x350.png 1024w, https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.49.41-768x263.png 768w, https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.49.41-1536x526.png 1536w, https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.49.41-2048x701.png 2048w, https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.49.41-954x326.png 954w, https:\/\/artem.services\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-23-at-19.49.41-1354x463.png 1354w\" sizes=\"(max-width: 2110px) 100vw, 2110px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; To select a Python version in the pipeline, you need to have the required versions installed on the system. Further actions were performed on CentOS 7 and the installation of binaries took place in the &quot;\/usr\/bin\/&quot; directory for convenience, since the system already has versions &quot;2.7&quot; and &quot;3.6&quot; installed from the repository along this &hellip; <a href=\"https:\/\/artem.services\/?p=2264&#038;lang=en\" class=\"more-link\">\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0442\u044c<span class=\"screen-reader-text\"> &quot;\u00a0Jenkins &#8212; Python VirtualEnv with version selection&quot;<\/span><\/a><\/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,1247,1841,1527],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/2264"}],"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=2264"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/2264\/revisions"}],"predecessor-version":[{"id":2266,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/2264\/revisions\/2266"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}