每1秒运行一次cURL命令,直到满足条件

时间:2020-03-10 04:36:57

标签: curl jenkins-pipeline docker-image

创建票证后,我需要不断检查状态(每1秒),直到它以const data = [ [ {}, { Country: 'Japan', cityName: 'tokyo', onto: [ { level1: 'one', articles: [ null, { id: '114506604', name: 'bunya3', abc: [ { filename: 'attachmentsfilename3', size: 3 } ], image: {} } ] } ] } ], [{}] ] function clean(input) { return input .map(item => { // remove empty arrays if (Array.isArray(item) && item.length === 0) { return null } // Remove empty objects if (item instanceof Object && Object.keys(item).length === 0) { return null } return item }) .filter(item => item) } console.log(clean(data)) approved的形式返回。然后,我要退出循环。有人知道这样做的干净方法吗?

rejected

1 个答案:

答案 0 :(得分:1)

您可以使用while循环尝试此操作。.我相信它可以工作..
//检查票证状态

withCredentials([string(credentialsId: JENKINS_API_KEY, variable: 'API_KEY')]) 
{
  while ({
   cmd = "curl -X GET -H 'x-api-key:${API_KEY}' '${URL}/requests/${REQUEST_ID}'  | jq -r '.requestStatus'"
   REQUEST_STATUS = sh(script:cmd, returnStdout: true).trim()
   print(REQUEST_STATUS)
   sleep('time': 1,'unit':"SECONDS")
   !["approved","rejected"].contains(REQUEST_STATUS)     
 }()) continue
 }