I try to perform the following code in a postbuild Jenkins task:
我尝试在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")'
(Here it is broken up over several lines for readability):
(为了便于阅读,这里分为几行):
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")'
This is not working because the environment variable ${env.SUBSYSTEM}
is not solved. Is there anyway for use variables in curl with the aql?
这不起作用,因为环境变量$ {env.SUBSYSTEM}未解决。无论如何使用aql在curl中使用变量?
Thanks and Regards
感谢致敬
1 个解决方案
#1
1
It's probably not resolving the environment variable because you're wrapping that piece of string in single quotes ('
), which preserve the literal value of each character within the quotes (meaning variables aren't resolved). You could use double quotes ("
) with escaping, which would look like:
它可能无法解析环境变量,因为您将这段字符串包装在单引号(')中,这保留了引号中每个字符的字面值(意味着变量未解析)。您可以使用带引号的双引号(“),它看起来像:
... -d "items.find({\"repo\":{\"$eq\":\"REPO\"},\"name\":{\"$match\":\"*${env.SUBSYSTEM}*\"},\"name\":{\"$nmatch\":\"*pdf*\"}}).include(\"repo\",\"name\",\"path\")"
Or possibly just break the environment variable out of the quoting:
或者可能只是从引用中打破环境变量:
... -d 'items.find({"repo":{"$eq":"REPO"},"name":{"$match":"*'${env.SUBSYSTEM}'*"},"name":{"$nmatch":"*pdf*"}}).include("repo","name","path")'
#1
1
It's probably not resolving the environment variable because you're wrapping that piece of string in single quotes ('
), which preserve the literal value of each character within the quotes (meaning variables aren't resolved). You could use double quotes ("
) with escaping, which would look like:
它可能无法解析环境变量,因为您将这段字符串包装在单引号(')中,这保留了引号中每个字符的字面值(意味着变量未解析)。您可以使用带引号的双引号(“),它看起来像:
... -d "items.find({\"repo\":{\"$eq\":\"REPO\"},\"name\":{\"$match\":\"*${env.SUBSYSTEM}*\"},\"name\":{\"$nmatch\":\"*pdf*\"}}).include(\"repo\",\"name\",\"path\")"
Or possibly just break the environment variable out of the quoting:
或者可能只是从引用中打破环境变量:
... -d 'items.find({"repo":{"$eq":"REPO"},"name":{"$match":"*'${env.SUBSYSTEM}'*"},"name":{"$nmatch":"*pdf*"}}).include("repo","name","path")'