For a parameterized assembly with an image tag selection, you will need the Active Choices plugin
Go to "Manage Jenkins"
Section "Manage Plugins"
Go to the "Available" tab and select "Active Choices" in the search.
Install it.
Create a "New Item" – "Pipeline", indicate that it will be a parameterized assembly, and add the parameter "Active Choices Reactive Parameter"
We indicate that this is "Groovy Script" and paste the following into it:
import com.amazonaws.client.builder.AwsClientBuilder; import com.amazonaws.services.ecr.AmazonECR; import com.amazonaws.services.ecr.AbstractAmazonECR; import com.amazonaws.services.ecr.AmazonECRClient; import com.amazonaws.services.ecr.model.ListImagesRequest; import com.amazonaws.services.ecr.model.ListImagesResult; import com.amazonaws.services.ecr.AmazonECRClientBuilder; import com.amazonaws.regions.Region; import com.amazonaws.regions.RegionUtils; import com.amazonaws.regions.Regions; import jenkins.model.* AmazonECR client = AmazonECRClientBuilder.standard().withRegion("eu-west-1").build(); ListImagesRequest request = new ListImagesRequest().withRepositoryName("artem-services"); res = client.listImages(request); def result = [] for (image in res) { result.add(image.getImageIds()); } return result[0].imageTag;
Where, "eu-west-1" – region where the ECR repository is located;
"artem-services" – the name of your ECR repository;
The same thing, but already in Pipeline
Pipeline:
properties([ parameters([ [$class: 'CascadeChoiceParameter', choiceType: 'PT_SINGLE_SELECT', description: 'Select Image', filterLength: 1, filterable: false, name: 'ImageTag', script: [ $class: 'GroovyScript', script: [ classpath: [], sandbox: false, script: ''' import com.amazonaws.client.builder.AwsClientBuilder; import com.amazonaws.services.ecr.AmazonECR; import com.amazonaws.services.ecr.AbstractAmazonECR; import com.amazonaws.services.ecr.AmazonECRClient; import com.amazonaws.services.ecr.model.ListImagesRequest; import com.amazonaws.services.ecr.model.ListImagesResult; import com.amazonaws.services.ecr.AmazonECRClientBuilder; import com.amazonaws.regions.Region; import com.amazonaws.regions.RegionUtils; import com.amazonaws.regions.Regions; import jenkins.model.* AmazonECR client = AmazonECRClientBuilder.standard().withRegion("eu-west-1").build(); ListImagesRequest request = new ListImagesRequest().withRepositoryName("artem-services"); res = client.listImages(request); def result = [] for (image in res) { result.add(image.getImageIds()); } return result[0].imageTag; ''' ] ] ] ]) ])
Artem ti KRUT!
Artem hi! it’s very helpful thanks!
But how to do sorting tags by to date?