You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Jenkins构建后任务中执行含环境变量的Artifactory AQL查询

Troubleshooting Your Jenkins + Artifactory AQL Query

Let's break down the common issues you might be hitting with this curl command in your Jenkins post-build task, and fix them step by step:

1. Jenkins Environment Variable Parsing Issue

First off, the way you reference Jenkins environment variables depends on the execution shell:

  • For Linux/macOS shell (Execute Shell step), drop the env. prefix — use ${SUBSYSTEM} instead of ${env.SUBSYSTEM}. The env. syntax is specific to Jenkins Pipeline scripts, not raw shell commands.
  • For Windows Batch (Execute Windows batch command), use %SUBSYSTEM% instead.
  • If you're using a Jenkins Pipeline sh step, you can still use ${SUBSYSTEM}, but make sure your curl command is wrapped appropriately to let the shell resolve the variable.

2. Broken AQL Syntax

Your AQL has duplicate name keys, which will be ignored by Artifactory (JSON doesn't allow duplicate keys). Merge these into a single $and condition to apply both matching rules:

items.find(
  {
    "repo": {"$eq": "REPO"},
    "$and": [
      {"name": {"$match": "*${SUBSYSTEM}*"}},
      {"name": {"$nmatch": "*pdf*"}}
    ]
  }
).include("repo","name","path")

3. Curl Command Escaping & Formatting

When passing the AQL string via curl's -d flag, you need to handle shell escaping correctly to ensure the variable is resolved while keeping the AQL valid:

  • Use single quotes for the AQL base string, then break out of single quotes to insert the variable (wrapped in double quotes for safety):
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"},
      "$and": [
        {"name": {"$match": "*'"${SUBSYSTEM}"'*"}},
        {"name": {"$nmatch": "*pdf*"}}
      ]
    }
  ).include("repo","name","path")'

4. Quick Validation Steps

Before debugging further in Jenkins:

  1. Verify the variable exists: Add an echo ${SUBSYSTEM} line before your curl command in the post-build task to confirm Jenkins is setting the variable correctly.
  2. Test locally: Run the curl command on your machine (replace ${SUBSYSTEM} with a real value) to confirm the AQL works with your Artifactory instance and API key.
  3. Check permissions: Ensure your API key has read access to the REPO repository — a 403 error in the Jenkins logs means permission issues.

Full Working Example (Linux Shell)

Here's a complete, validated script you can drop into your Execute Shell post-build task:

# Confirm the subsystem variable is set
echo "Using SUBSYSTEM value: ${SUBSYSTEM}"

# Execute the fixed AQL query
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"},
      "$and": [
        {"name": {"$match": "*'"${SUBSYSTEM}"'*"}},
        {"name": {"$nmatch": "*pdf*"}}
      ]
    }
  ).include("repo","name","path")'

If you still hit issues, check the Jenkins build logs for curl's raw output — it will show HTTP error codes or AQL syntax errors that point directly to the problem.

内容的提问来源于stack exchange,提问作者garci86

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:44:56