无法通过 Jenkins 打印名称中包含特定字符串的文件

Unable to print files containing specific string in their names through Jenkins

我正在尝试打印名称中包含 "jar-with-dependencies" 的所有文件的名称。我写了下面几行来做到这一点。

FOR /R serviceFolder %%G IN ("*jar-with-dependencies*.jar") DO (
set jarName="%%~nG"
echo %jarName%"
)

当我 运行 来自 bat 文件的以下代码时,它会 运行 并打印名称。但是当我从 Jenkins 执行此操作时,我收到一条错误消息 "The system cannot find the file specified." 我检查了 Jenkins 的文件夹位置并且我在正确的文件夹中。我在这里做错了什么?任何帮助将不胜感激。

第二次尝试,仍然没有成功:

FOR /R update-service %%G IN ("*jar-with-dependencies*.jar") DO (
set jarName="%%~fG"
echo "%jarName%"
)

第三次尝试,还是一样的错误。

SETLOCAL EnableDelayedExpansion
FOR /R update-service %%G IN ("*jar-with-dependencies*.jar") DO (
set "jarName=%%~fG"
echo "%jarName%"
)

Whosebug and SuperUser related to the [batch-file] 标签中最常见的问题之一:

SETLOCAL EnableDelayedExpansion
FOR /R update-service %%G IN ("*jar-with-dependencies*.jar") DO (
    set "jarName=%%~fG"
    echo "!jarName!"
)

参考:Delayed Expansion