带有Jenkins环境变量的Artifactory API AQL

时间:2018-05-03 14:26:27

标签: jenkins environment-variables artifactory aql

我尝试在postbuild Jenkins任务中执行以下代码:

curl -H "X-JFrog-Art-Api:***********" -X POST https://artifactory_url/artifactory/api/search/aql -H "Content-Type: text/plain" -d 'items.find({"repo":{"$eq":"REPO"},"name":{"$match":"*${env.SUBSYSTEM}*"},"name":{"$nmatch":"*pdf*"}}).include("repo","name","path")'

(为了便于阅读,这里分为几行:

curl -X POST https://artifactory_url/artifactory/api/search/aql \
     -H "X-JFrog-Art-Api:***********" \
     -H "Content-Type: text/plain" \
     -d 'items.find( \
         {"repo":{"$eq":"REPO"}, \
          "name":{"$match":"*${env.SUBSYSTEM}*"}, \
          "name":{"$nmatch":"*pdf*"}}).include("repo","name","path")'

这不起作用,因为环境变量${env.SUBSYSTEM}未解决。无论如何使用aql在curl中使用变量?

谢谢和问候

1 个答案:

答案 0 :(得分:1)

它可能无法解析环境变量,因为您将这段字符串包装在单引号(')中,这会保留引号中每个字符的字面值(意味着变量未解析)。您可以使用双引号(")进行转义,如下所示:

... -d "items.find({\"repo\":{\"$eq\":\"REPO\"},\"name\":{\"$match\":\"*${env.SUBSYSTEM}*\"},\"name\":{\"$nmatch\":\"*pdf*\"}}).include(\"repo\",\"name\",\"path\")"

或者可能只是从引用中删除环境变量:

... -d 'items.find({"repo":{"$eq":"REPO"},"name":{"$match":"*'${env.SUBSYSTEM}'*"},"name":{"$nmatch":"*pdf*"}}).include("repo","name","path")'