Git 如何在jenkins sh命令中使用groovy变量

Git 如何在jenkins sh命令中使用groovy变量,git,shell,jenkins,groovy,continuous-integration,Git,Shell,Jenkins,Groovy,Continuous Integration,我试图在Jenkins文件中使用groovy变量,如下所示 def since='2018-06-01'; count = sh(returnStdout: true, script: 'git rev-list --all --count master --since="${since}"').trim(); 因为变量未在Jenkins输出中计算 + git rev-list --all --count master --since= [Pipeline] echo 看起来我的语法有问题。

我试图在Jenkins文件中使用groovy变量,如下所示

def since='2018-06-01';
count = sh(returnStdout: true, script: 'git rev-list --all --count master --since="${since}"').trim();
因为变量未在Jenkins输出中计算

+ git rev-list --all --count master --since=
[Pipeline] echo

看起来我的语法有问题。有人能帮上忙吗。

如果要在字符串中插入Groovy变量,则必须使用双引号(单引号创建
string
,而双引号创建
GString
):

此外,如果您想通过
--since=“2018-06-01”
,则必须像上面的示例中那样转义
\

更新的代码生成以下git命令:

+ git rev-list --all --count master --since="2018-06-01"
+ git rev-list --all --count master --since="2018-06-01"