小编Keb*_*bbi的帖子

Javascript:如何将找到的string.replace值传递给函数?

当我有这样的事情:

var str = "0123";
var i = 0;
str.replace(/(\d)/g,function(s){i++;return s;}('$1'));
alert(i);
Run Code Online (Sandbox Code Playgroud)

为什么"i"等于1而不是4?另外,是否可以将$ 1的实际值传递给函数(在本例中为0,1,2,3)?

javascript regex replace function

3
推荐指数
1
解决办法
7306
查看次数

Jenkins Pipelines:为什么CPS Global Lib没有加载?

我正在关注管道库插件的教程.我创建了一个包含以下文件的存储库:

D:.
?   Test.groovy
?   
????src
????vars
        helloWorld.groovy
Run Code Online (Sandbox Code Playgroud)

helloWorld.groovy包含:

def call(name){
    echo "Hello world, ${name}"
}
Run Code Online (Sandbox Code Playgroud)

Test.groovy包含:

helloWorld("Joe")
Run Code Online (Sandbox Code Playgroud)

我安装了所有管道插件,特别是workflow-cps-global-lib-plugin.然后我创建了一个新的管道作业,在其中加载此存储库并将脚本路径设置为Test.groovy.当我运行这个工作时,我收到以下错误:

java.lang.NoSuchMethodError: No such DSL method 'helloWorld' found among [archive, bat, build, catchError, checkout, deleteDir, dir, echo, emailext, error, fileExists, git, input, isUnix, jiraComment, jiraIssueSelector, jiraSearch, load, mail, node, parallel, properties, pwd, readFile, readTrusted, retry, sh, sleep, stage, stash, step, svn, timeout, tool, unarchive, unstash, waitUntil, withEnv, wrap, writeFile, ws]
Run Code Online (Sandbox Code Playgroud)

为什么没有定义helloWorld步骤?这是我安装的插件列表:http://pastebin.com/xiMMub8J

jenkins jenkins-pipeline

2
推荐指数
1
解决办法
2481
查看次数