Как оценить долларовое выражение в groovy и сохранить значение - PullRequest
0 голосов
/ 01 октября 2019

У меня есть потребность, где мне нужно получить Revision для определения задачи в AWS, используя мой каверзный файл Jenkinsfile. Нижеследующее работает для меня под сценарием оболочки, но я не смог заставить его работать для моего отличного Jenkinsfile. Другие переменные, такие как props.region и т. Д., Взяты из файла свойств, и я уже получаю их, используя: -

def call(Map config=[:]) {
    def deployDefinition = libraryResource "deployDefinitions/ecs/${config.deployApplication}/${config.deployEnvironment}.properties"
    def props = readProperties(text:deployDefinition)
    
    withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: "${props.awsCreds}", secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
    
    def newimageurl = "${props.registry}/${props.imagename}:${IMAGE_TAG}"
    def oldimageurl = "${props.registry}/${props.imagename}"
    
    sh "sed -i -e 's#${oldimageurl}#${newimageurl}#' ./taskdef.json"
      
   sh "aws ecs register-task-definition --family ${props.family} --cli-input-json file://${WORKSPACE}/taskdef.json --region ${props.region}"
   REVISION=$(aws ecs describe-task-definition --task-definition ${props.task_def_name} --region ${props.region} | jq .taskDefinition.revision)
   sh "aws ecs update-service --cluster ${props.cluster} --region ${props.region} --service ${props.service_name} --task-definition ${props.task_def_name}:$REVISION"
}
}

REVISION=$(aws ecs describe-task-definition --task-definition ${props.task_def_name} --region ${props.region} | jq .taskDefinition.revision)

Все, что я ищу, - это как получить фактическое значение для REVISION, чтобы я мог передать это значение в моей следующей команде, которая должна обновить службу

1 Ответ

0 голосов
/ 01 октября 2019

Я смог заставить это работать, используя следующий подход: -

sh "aws ecs describe-task-definition --task-definition ${props.task_def_name} --region ${props.region} | jq .taskDefinition.revision > output.txt"
def REVISION = readFile "${WORKSPACE}/output.txt"
sh "aws ecs update-service --cluster ${props.cluster} --region ${props.region} --service ${props.service_name} --task-definition ${props.task_def_name}:$REVISION"
...