
Для параметризованной сборки, понадобится плагин Active Choices
Переходим в настройки Jenkins‘а

Раздел «Управление плагинами»

Переходим к вкладке «Доступные» и в поиске указываем «Active Choices»

Устанавливаем его.
Создаем «New Item» — «Pipeline«, указываем, что это будет параметризованная сборка, и добавляем параметр «Active Choices Parameter»

Указываем, что это «Groovy Script» и вставляем туда следующее:
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.S3Object;
import com.cloudbees.plugins.credentials.Credentials;
import com.cloudbees.plugins.credentials.CredentialsNameProvider;
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import com.cloudbees.jenkins.plugins.awscredentials.AmazonWebServicesCredentials;
import groovy.json.JsonSlurper;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;
import jenkins.model.*
def AWS_REGION = 'eu-west-1'
def BUCKET_NAME = 'artem.services'
def INFO_FILE = 'info.json'
credentialsId = 'aws_credentials'
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(AmazonWebServicesCredentials.class, Jenkins.instance, null, null ).find({it.id == credentialsId});
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(creds).withRegion(AWS_REGION).build();
S3Object s3Object = s3Client.getObject(BUCKET_NAME, INFO_FILE)
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(s3Object.getObjectContent()))
s3Data = reader.lines().collect(Collectors.joining("\n"));
} catch (Exception e) {
System.err.println(e.getMessage());
System.exit(1);
}
def json = new JsonSlurper().parseText(s3Data)
return json.instance.ip
Где значение переменных, «credentialsId» — Jenkins Credentials ID с AWS Access Key и AWS Secret Key (если для Jenkins инстанса не используется IAM Role, или он развернут не в AWS Cloud);
«AWS_REGION» — AWS регион, где находится S3 Bucket;
«BUCKET_NAME» — имя S3 бакета;
«INFO_FILE» — ключ объекта в корзине, в нашем случае JSON файла;
«return json.instance.ip» — возвращаем значение ключа instance: {‘ip’: »1.2.3.4}