我正在尝试编写一个 Hello World Maven 插件。
我分配defaultPhase=LifecyclePhase.CLEAN给它,但当我执行时mvn clean它不起作用。
当我执行时mvn gorov:clean它正在工作。
有什么建议么?
DS
代码是:
项目中的位置:maven-plugin\src\main\java\com\gorovdude\plugins\maven\mojos\WriteConsoleMojo.java
package com.gorovdude.plugins.maven.mojos;
import java.io.File;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
@Mojo(name = "clean", defaultPhase = LifecyclePhase.CLEAN, threadSafe = true, aggregator = true)
public class WriteConsoleMojo extends AbstractMojo {
public void execute() throws MojoExecutionException, MojoFailureException {
try {
String path = "C:\\Apache-maven-3.2.5\\testing.txt";
System.out.println("testing");
File f = new File(path);
f.createNewFile();
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), …Run Code Online (Sandbox Code Playgroud) 我想删除以AAA开头的Jenkins作业列表(例如)
当我用显式字符串做它时它工作正常
if (item.name ==~ /AAA.*/){
item.delete()
}
Run Code Online (Sandbox Code Playgroud)
但是当我试图从Jenkins Build属性中获取正则表达式时,我失败了并且没有调用if ...
import hudson.model.*
import hudson.node_monitors.*
import hudson.slaves.*
import java.util.concurrent.*
jenkins = Hudson.instance
def thr = Thread.currentThread()
def build = thr?.executable
String REGEX = build.environment.get("Include_Regex")
println "REGEX is " + REGEX
for (item in jenkins.items){
println("\t ${item.name}");
println("\t ${item.name.getClass()}");
if (item.name ==~ REGEX){
item.delete()
println("TEST");
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我得到所有作业的列表:在工作区中构建/ var/lib/jenkins/jobs/Bulk_Delete_Job/workspace
REGEX is /AAA.*/
AAA_test_1
class java.lang.String
AAA_test_2
class java.lang.String
AAA_test_3
class java.lang.String
Bulk_Delete_Job
class java.lang.String
ConfiguredJob
class java.lang.String
JobZ
class java.lang.String
TEST_SCM …Run Code Online (Sandbox Code Playgroud)