问题描述
在詹金斯管道中
variant 从作业配置中读取为
getAllUsers: async () => {
let dbRes;
try {
await client.connect();
console.log("here 1",dbRes)
const collection = client.db("InternManager").collection("Users");
dbRes = await collection.find().toArray()
console.log("here 2",dbRes)
return dbRes;
} catch(err: any) {
throw err; // If you're just catching and throwing the error,then it would be okay to just ignore it
}
},
variant 可以是“abc”或“xyz”,具体取决于在作业配置中输入的内容。
variant = job_config['variant']
让我们假设变量在作业配置中被指定为“abc”。 即使 'tmp/build/abc/bin/Test.xml' 真实存在,
在 jenkins 构建期间,'tmp/build/${variant}/bin/Test.xml 的条件检查文件按原样读取,即 ${variant} 不会被替换为 abc 在条件检查期间。
你能帮我解决这个问题吗?谢谢!
解决方法
您可能需要在路径中使用双引号而不是单引号:
if(fileExists("tmp/build/${variant}/bin/Test.xml"))
以便将变量替换为其值。
Jenkins 管道是用 groovy 编写的,因此您可以在 this 问题和 the official groovy documentation 中找到有关 groovy 中单引号和双引号之间区别的更多信息。