{"id":1910,"date":"2020-04-15T13:59:15","date_gmt":"2020-04-15T10:59:15","guid":{"rendered":"https:\/\/artem.services\/?p=1889"},"modified":"2020-04-15T16:50:49","modified_gmt":"2020-04-15T13:50:49","slug":"1910","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=1910&lang=en","title":{"rendered":"Jenkins &#8212; Active Choice: AWS ECR Images tag (AWS SDK)"},"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>For a parameterized assembly with an image tag selection, you will need the <a href=\"https:\/\/plugins.jenkins.io\/uno-choice\/\" target=\"_blank\" rel=\"noopener noreferrer\">Active Choices<\/a> plugin<\/p>\n<p>Go to &quot;<strong>Manage Jenkins<\/strong>&quot;<\/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>Section &quot;<strong>Manage Plugins<\/strong>&quot;<\/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>Go to the &quot;<strong>Available<\/strong>&quot; tab and select &quot;<strong>Active Choices<\/strong>&quot; in the search.<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1796\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-01-at-10.55.37.png\" alt=\"\" width=\"1412\" height=\"130\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-01-at-10.55.37.png 1412w, https:\/\/artem.services\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-01-at-10.55.37-300x28.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-01-at-10.55.37-1024x94.png 1024w, https:\/\/artem.services\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-01-at-10.55.37-768x71.png 768w, https:\/\/artem.services\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-01-at-10.55.37-954x88.png 954w, https:\/\/artem.services\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-01-at-10.55.37-1354x125.png 1354w\" sizes=\"(max-width: 1412px) 100vw, 1412px\" \/><\/p>\n<p>Install it.<\/p>\n<p>Create a &quot;<strong>New Item<\/strong>&quot; &#8212; &quot;<strong>Pipeline<\/strong>&quot;, indicate that it will be a parameterized assembly, and add the parameter &quot;<strong>Active Choices Reactive Parameter<\/strong>&quot;<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1803\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2020\/04\/004.png\" alt=\"\" width=\"445\" height=\"379\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2020\/04\/004.png 445w, https:\/\/artem.services\/wp-content\/uploads\/2020\/04\/004-300x256.png 300w\" sizes=\"(max-width: 445px) 100vw, 445px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>We indicate that this is &quot;<strong>Groovy Script<\/strong>&quot; and paste the following into it:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nimport com.amazonaws.client.builder.AwsClientBuilder;\r\nimport com.amazonaws.services.ecr.AmazonECR;\r\nimport com.amazonaws.services.ecr.AbstractAmazonECR;\r\nimport com.amazonaws.services.ecr.AmazonECRClient;\r\nimport com.amazonaws.services.ecr.model.ListImagesRequest;\r\nimport com.amazonaws.services.ecr.model.ListImagesResult;\r\nimport com.amazonaws.services.ecr.AmazonECRClientBuilder;\r\nimport com.amazonaws.regions.Region;\r\nimport com.amazonaws.regions.RegionUtils;\r\nimport com.amazonaws.regions.Regions;\r\nimport jenkins.model.*\r\n\r\nAmazonECR client = AmazonECRClientBuilder.standard().withRegion(&quot;eu-west-1&quot;).build();\r\nListImagesRequest request = new ListImagesRequest().withRepositoryName(&quot;artem-services&quot;);\r\nres = client.listImages(request);\r\n\r\n\r\ndef result = []\r\nfor (image in res) {\r\n   result.add(image.getImageIds());\r\n}\r\n\r\nreturn result[0].imageTag;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<blockquote><p>Where, &quot;<strong>eu-west-1<\/strong>&quot; &#8212; region where the <strong>ECR<\/strong> repository is located;<\/p>\n<p>&quot;<strong>artem-services<\/strong>&quot; &#8212; the name of your <strong>ECR<\/strong> repository;<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>The same thing, but already in <strong>Pipeline<\/strong><\/p>\n<h3>Pipeline:<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nproperties([\r\n  parameters([\r\n    [$class: 'CascadeChoiceParameter', \r\n      choiceType: 'PT_SINGLE_SELECT', \r\n      description: 'Select Image',\r\n      filterLength: 1,\r\n      filterable: false,\r\n      name: 'ImageTag', \r\n      script: [\r\n        $class: 'GroovyScript', \r\n        script: [\r\n          classpath: [], \r\n          sandbox: false, \r\n          script: \r\n            '''\r\n            import com.amazonaws.client.builder.AwsClientBuilder;\r\n            import com.amazonaws.services.ecr.AmazonECR;\r\n            import com.amazonaws.services.ecr.AbstractAmazonECR;\r\n            import com.amazonaws.services.ecr.AmazonECRClient;\r\n            import com.amazonaws.services.ecr.model.ListImagesRequest;\r\n            import com.amazonaws.services.ecr.model.ListImagesResult;\r\n            import com.amazonaws.services.ecr.AmazonECRClientBuilder;\r\n            import com.amazonaws.regions.Region;\r\n            import com.amazonaws.regions.RegionUtils;\r\n            import com.amazonaws.regions.Regions;\r\n            import jenkins.model.*\r\n\r\n            AmazonECR client = AmazonECRClientBuilder.standard().withRegion(&quot;eu-west-1&quot;).build();\r\n            ListImagesRequest request = new ListImagesRequest().withRepositoryName(&quot;artem-services&quot;);\r\n            res = client.listImages(request);\r\n\r\n\r\n            def result = []\r\n            for (image in res) {\r\n               result.add(image.getImageIds());\r\n            }\r\n\r\n            return result[0].imageTag;\r\n            '''\r\n        ]\r\n      ]\r\n    ]\r\n  ])\r\n])\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; For a parameterized assembly with an image tag selection, you will need the Active Choices plugin Go to &quot;Manage Jenkins&quot; &nbsp; Section &quot;Manage Plugins&quot; &nbsp; Go to the &quot;Available&quot; tab and select &quot;Active Choices&quot; in the search. Install it. Create a &quot;New Item&quot; &#8212; &quot;Pipeline&quot;, indicate that it will be a parameterized assembly, and &hellip; <a href=\"https:\/\/artem.services\/?p=1910&#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;Jenkins &#8212; Active Choice: AWS ECR Images tag (AWS SDK)&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":[599,613],"tags":[1465,543,1581,879,1575,617,641,1247],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1910"}],"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=1910"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1910\/revisions"}],"predecessor-version":[{"id":1912,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1910\/revisions\/1912"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}