Jenkins 在页面加载时将值从config.xml加载到jelly文件
我的应用程序中有一个自定义表单,我想将值加载到它的字段中 为此,我有一个从ItemListener扩展而来的类,它通过创建一个Action对象、将该Action对象添加到项目中并保存项目,重写了OnUpdate方法来读取更新的配置文件并将值设置到文本框字段。出于某种原因,这不起作用。下面是代码片段 动作类:Jenkins 在页面加载时将值从config.xml加载到jelly文件,jenkins,config,jenkins-plugins,Jenkins,Config,Jenkins Plugins,我的应用程序中有一个自定义表单,我想将值加载到它的字段中 为此,我有一个从ItemListener扩展而来的类,它通过创建一个Action对象、将该Action对象添加到项目中并保存项目,重写了OnUpdate方法来读取更新的配置文件并将值设置到文本框字段。出于某种原因,这不起作用。下面是代码片段 动作类: public class MyAction<T extends AbstractItem> implements Action { final private T item; p
public class MyAction<T extends AbstractItem> implements Action {
final private T item;
public String gitRepo;
public String gitBranch;
public String mavenGoals;
public String mavenPOM;
public String eMailRecipient;
@DataBoundConstructor
public MyAction(T item, String gitRepo, String gitBranch, String mavenGoals, String mavenPOM, String eMailRecipient) {
this.item = item;
this.gitRepo = gitRepo;
this.gitBranch = gitBranch;
this.mavenGoals = mavenGoals;
this.mavenPOM = mavenPOM;
this.eMailRecipient = eMailRecipient;
}
//Getter methods follow...
@Extension
public class MyActionListener extends ItemListener{
@Override
public void onUpdated(Item item){
if(item instanceof AbstractItem)
{
for(Action action : Jenkins.getInstance().getActions())
if(action.getClass()==MyAction.class)
{
AbstractProject proj=(AbstractProject) item;
XmlFile projConfig=proj.getConfigFile();
String config=projConfig.toString();
String gitRepo=config.substring(config.indexOf("<url>")+5, config.indexOf("</url>"));
String branch=config.substring(config.indexOf("<name>")+6,config.indexOf("</name>"));
String mavengoals=config.substring(config.indexOf("<target>")+8,config.indexOf("<target>"));
String mavenPom=config.substring(config.indexOf("<pom>")+5,config.indexOf("</pom>"));
String eMailReceipient=config.substring(config.indexOf("<recipientList>")+15,config.indexOf("<recipientList>"));
Action newAction=new MyAction((AbstractItem) item,gitRepo,branch,mavengoals,mavenPom,eMailReceipient);
proj.addAction(newAction);
try {
proj.save();
} catch (IOException ex) {
Logger.getLogger(MyActionListener.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
<f:form method="post" name="config" action="configSubmit">
<f:block>
<f:section title="${%Job Configuration}">
<f:entry title="${%Job name}">
<f:textbox id="name" name="name" default="${it.ItemName}"/>
</f:entry>
</f:section>
<f:section title="${%Source Code Management}">
<f:entry title="${%Git Repo}">
<f:textbox id="repo" name="repo" default="git@github.scm.corp.mycompany.com:{Enter your git repo here}" value="${it.GitRepo}"/>
</f:entry>
<f:entry title="${%Branch}">
<f:textbox id="branch" name="branch" default="master" value="${it.GitBranch}"/>
</f:entry>
</f:section>
<f:section title="${%Maven Targets}">
<f:entry title="${%Goals}">
<f:textbox id="goals" name="goals" default="-U clean install" value="${it.MavenGoals}"/>
</f:entry>
<f:entry title="${%POM}">
<f:textbox id="pom" name="pom" default="pom.xml" value="${it.MavenPOM}"/>
</f:entry>
</f:section>
<f:section title="${%E-Mail Notification}">
<f:entry title="${%Recipient}">
<f:textbox id="emailrecipient" name="emailrecipient" default="QE DL For Notifying" value="${it.eMailRecipient}"/>
</f:entry>
</f:section>
<f:section title="${%Assembler Postbuild}">
<f:entry title="${%Assembler Target POM.xml{relative path}}">
<f:textbox id="assemblerpom" name="assemblerpom"/>
</f:entry>
</f:section>
</f:block>
<f:bottomButtonBar>
<f:submit value="${%Save}" />
</f:bottomButtonBar>
</f:form>
公共类MyAction实现操作{
最后一个私人项目;
公共字符串gitRepo;
公共部门;
公共字符串mavenGoals;
公共字符串mavenPOM;
公共字符串电子邮件收件人;
@数据边界构造函数
公共MyAction(T项、字符串gitRepo、字符串gitBranch、字符串mavenGoals、字符串mavenPOM、字符串eMailRecipient){
this.item=项目;
this.gitRepo=gitRepo;
this.gitBranch=gitBranch;
this.mavenGoals=mavenGoals;
this.mavenPOM=mavenPOM;
this.eMailRecipient=eMailRecipient;
}
//Getter方法如下。。。
ItemListener类:
public class MyAction<T extends AbstractItem> implements Action {
final private T item;
public String gitRepo;
public String gitBranch;
public String mavenGoals;
public String mavenPOM;
public String eMailRecipient;
@DataBoundConstructor
public MyAction(T item, String gitRepo, String gitBranch, String mavenGoals, String mavenPOM, String eMailRecipient) {
this.item = item;
this.gitRepo = gitRepo;
this.gitBranch = gitBranch;
this.mavenGoals = mavenGoals;
this.mavenPOM = mavenPOM;
this.eMailRecipient = eMailRecipient;
}
//Getter methods follow...
@Extension
public class MyActionListener extends ItemListener{
@Override
public void onUpdated(Item item){
if(item instanceof AbstractItem)
{
for(Action action : Jenkins.getInstance().getActions())
if(action.getClass()==MyAction.class)
{
AbstractProject proj=(AbstractProject) item;
XmlFile projConfig=proj.getConfigFile();
String config=projConfig.toString();
String gitRepo=config.substring(config.indexOf("<url>")+5, config.indexOf("</url>"));
String branch=config.substring(config.indexOf("<name>")+6,config.indexOf("</name>"));
String mavengoals=config.substring(config.indexOf("<target>")+8,config.indexOf("<target>"));
String mavenPom=config.substring(config.indexOf("<pom>")+5,config.indexOf("</pom>"));
String eMailReceipient=config.substring(config.indexOf("<recipientList>")+15,config.indexOf("<recipientList>"));
Action newAction=new MyAction((AbstractItem) item,gitRepo,branch,mavengoals,mavenPom,eMailReceipient);
proj.addAction(newAction);
try {
proj.save();
} catch (IOException ex) {
Logger.getLogger(MyActionListener.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
<f:form method="post" name="config" action="configSubmit">
<f:block>
<f:section title="${%Job Configuration}">
<f:entry title="${%Job name}">
<f:textbox id="name" name="name" default="${it.ItemName}"/>
</f:entry>
</f:section>
<f:section title="${%Source Code Management}">
<f:entry title="${%Git Repo}">
<f:textbox id="repo" name="repo" default="git@github.scm.corp.mycompany.com:{Enter your git repo here}" value="${it.GitRepo}"/>
</f:entry>
<f:entry title="${%Branch}">
<f:textbox id="branch" name="branch" default="master" value="${it.GitBranch}"/>
</f:entry>
</f:section>
<f:section title="${%Maven Targets}">
<f:entry title="${%Goals}">
<f:textbox id="goals" name="goals" default="-U clean install" value="${it.MavenGoals}"/>
</f:entry>
<f:entry title="${%POM}">
<f:textbox id="pom" name="pom" default="pom.xml" value="${it.MavenPOM}"/>
</f:entry>
</f:section>
<f:section title="${%E-Mail Notification}">
<f:entry title="${%Recipient}">
<f:textbox id="emailrecipient" name="emailrecipient" default="QE DL For Notifying" value="${it.eMailRecipient}"/>
</f:entry>
</f:section>
<f:section title="${%Assembler Postbuild}">
<f:entry title="${%Assembler Target POM.xml{relative path}}">
<f:textbox id="assemblerpom" name="assemblerpom"/>
</f:entry>
</f:section>
</f:block>
<f:bottomButtonBar>
<f:submit value="${%Save}" />
</f:bottomButtonBar>
</f:form>
@扩展名
公共类MyActionListener扩展了ItemListener{
@凌驾
未更新的公共无效(项目){
if(抽象项的项实例)
{
对于(操作:Jenkins.getInstance().getActions())
if(action.getClass()==MyAction.class)
{
AbstractProject项目=(AbstractProject)项;
XmlFile projConfig=proj.getConfigFile();
String config=projConfig.toString();
字符串gitRepo=config.substring(config.indexOf(“”+5,config.indexOf(“”));
String branch=config.substring(config.indexOf(“”+6,config.indexOf(“”));
字符串mavengoals=config.substring(config.indexOf(“”+8,config.indexOf(“”));
字符串mavenPom=config.substring(config.indexOf(“”+5,config.indexOf(“”));
字符串emailReceipent=config.substring(config.indexOf(“”+15,config.indexOf(“”));
Action newAction=newmyaction((AbstractItem)项、gitRepo、branch、mavengoals、mavenPom、emailreceipent);
项目添加操作(新操作);
试一试{
项目保存();
}捕获(IOEX异常){
Logger.getLogger(MyActionListener.class.getName()).log(Level.SEVERE,null,ex);
}
}
}
}
}
果冻状:
public class MyAction<T extends AbstractItem> implements Action {
final private T item;
public String gitRepo;
public String gitBranch;
public String mavenGoals;
public String mavenPOM;
public String eMailRecipient;
@DataBoundConstructor
public MyAction(T item, String gitRepo, String gitBranch, String mavenGoals, String mavenPOM, String eMailRecipient) {
this.item = item;
this.gitRepo = gitRepo;
this.gitBranch = gitBranch;
this.mavenGoals = mavenGoals;
this.mavenPOM = mavenPOM;
this.eMailRecipient = eMailRecipient;
}
//Getter methods follow...
@Extension
public class MyActionListener extends ItemListener{
@Override
public void onUpdated(Item item){
if(item instanceof AbstractItem)
{
for(Action action : Jenkins.getInstance().getActions())
if(action.getClass()==MyAction.class)
{
AbstractProject proj=(AbstractProject) item;
XmlFile projConfig=proj.getConfigFile();
String config=projConfig.toString();
String gitRepo=config.substring(config.indexOf("<url>")+5, config.indexOf("</url>"));
String branch=config.substring(config.indexOf("<name>")+6,config.indexOf("</name>"));
String mavengoals=config.substring(config.indexOf("<target>")+8,config.indexOf("<target>"));
String mavenPom=config.substring(config.indexOf("<pom>")+5,config.indexOf("</pom>"));
String eMailReceipient=config.substring(config.indexOf("<recipientList>")+15,config.indexOf("<recipientList>"));
Action newAction=new MyAction((AbstractItem) item,gitRepo,branch,mavengoals,mavenPom,eMailReceipient);
proj.addAction(newAction);
try {
proj.save();
} catch (IOException ex) {
Logger.getLogger(MyActionListener.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
<f:form method="post" name="config" action="configSubmit">
<f:block>
<f:section title="${%Job Configuration}">
<f:entry title="${%Job name}">
<f:textbox id="name" name="name" default="${it.ItemName}"/>
</f:entry>
</f:section>
<f:section title="${%Source Code Management}">
<f:entry title="${%Git Repo}">
<f:textbox id="repo" name="repo" default="git@github.scm.corp.mycompany.com:{Enter your git repo here}" value="${it.GitRepo}"/>
</f:entry>
<f:entry title="${%Branch}">
<f:textbox id="branch" name="branch" default="master" value="${it.GitBranch}"/>
</f:entry>
</f:section>
<f:section title="${%Maven Targets}">
<f:entry title="${%Goals}">
<f:textbox id="goals" name="goals" default="-U clean install" value="${it.MavenGoals}"/>
</f:entry>
<f:entry title="${%POM}">
<f:textbox id="pom" name="pom" default="pom.xml" value="${it.MavenPOM}"/>
</f:entry>
</f:section>
<f:section title="${%E-Mail Notification}">
<f:entry title="${%Recipient}">
<f:textbox id="emailrecipient" name="emailrecipient" default="QE DL For Notifying" value="${it.eMailRecipient}"/>
</f:entry>
</f:section>
<f:section title="${%Assembler Postbuild}">
<f:entry title="${%Assembler Target POM.xml{relative path}}">
<f:textbox id="assemblerpom" name="assemblerpom"/>
</f:entry>
</f:section>
</f:block>
<f:bottomButtonBar>
<f:submit value="${%Save}" />
</f:bottomButtonBar>
</f:form>
这是个问题吗?你想知道什么?