diff --git a/pom.xml b/pom.xml index 67d60f0..0974604 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ ${revision}${changelist} hpi Jenkins ConfigOps Plugin - https://github.com/jenkinsci/${project.artifactId}-plugin + https://github.com/dumasd/${project.artifactId} MIT License diff --git a/src/main/java/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep.java b/src/main/java/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep.java index 7ad3e07..d46f07b 100644 --- a/src/main/java/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep.java +++ b/src/main/java/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep.java @@ -58,10 +58,6 @@ public class LiquibaseRawCmdStep extends Step implements Serializable { * Database ID */ private final String databaseId; - /** - * 在哪个路径下执行 - */ - private String cwd; /** * Liquibase命令 */ @@ -70,6 +66,14 @@ public class LiquibaseRawCmdStep extends Step implements Serializable { * Liquibase命令参数 */ private final String args; + /** + * changeLogFile文件 + */ + private String changeLogFile; + /** + * 在哪个路径下执行 + */ + private String cwd; @DataBoundConstructor public LiquibaseRawCmdStep( @@ -81,6 +85,16 @@ public LiquibaseRawCmdStep( this.args = args; } + @DataBoundSetter + public void setToolUrl(String toolUrl) { + this.toolUrl = toolUrl; + } + + @DataBoundSetter + public void setChangeLogFile(String changeLogFile) { + this.changeLogFile = changeLogFile; + } + @DataBoundSetter public void setCwd(String cwd) { this.cwd = cwd; @@ -113,6 +127,12 @@ protected Map run() throws Exception { cwdPath = workspace.child(step.getCwd()); } + String changeLogFile = null; + if (StringUtils.isNotBlank(step.getChangeLogFile())) { + FilePath changeLogFilePath = workspace.child(step.getChangeLogFile()); + changeLogFile = changeLogFilePath.getRemote(); + } + Logger logger = new Logger("LiquibaseCommand", taskListener); logger.log( @@ -120,7 +140,7 @@ protected Map run() throws Exception { Util.fixNull(step.getCwd()), step.getCommand(), Util.fixNull(step.getArgs())); DatabaseRunLiquibaseResp resp = cwdPath.act(new RemoteExecutionCallable( - step.getToolUrl(), step.getDatabaseId(), step.getCommand(), step.getArgs())); + step.getToolUrl(), step.getDatabaseId(), step.getCommand(), step.getArgs(), changeLogFile)); logger.log("Liquibase run command return code: %s", resp.getRetcode()); if (StringUtils.isNotBlank(resp.getStderr())) { @@ -142,12 +162,15 @@ public static class RemoteExecutionCallable extends MasterToSlaveFileCallable vars) { this.vars = vars; } + @DataBoundSetter + public void setVars(String vars) { + String strippedChoices = StringUtils.trim(vars); + HashMap result = new LinkedHashMap<>(); + if (StringUtils.isNotBlank(strippedChoices)) { + List choices = Arrays.stream(strippedChoices.split(CHOICES_DELIMITER)) + .map(StringUtils::trim) + .filter(StringUtils::isNotBlank) + .distinct() + .collect(Collectors.toList()); + for (String choice : choices) { + String[] kv = choice.split(":"); + result.put(kv[0], kv[1]); + } + } + this.vars = result; + } + @Override public StepExecution start(StepContext context) throws Exception { return new StepExecutionImpl(context, this); @@ -173,5 +205,69 @@ public String getDisplayName() { public String getFunctionName() { return "nacosChangeSetGet"; } + + @POST + public FormValidation doCheckNacosId(@QueryParameter("nacosId") String nacosId) { + if (Utils.isNullOrEmpty(nacosId)) { + return FormValidation.error("NacosId is required"); + } + return FormValidation.ok(); + } + + @POST + public FormValidation doCheckChangeLogFile(@QueryParameter("changeLogFile") String changeLogFile) { + if (Utils.isNullOrEmpty(changeLogFile)) { + return FormValidation.error("ChangeLogFile is required"); + } + return FormValidation.ok(); + } + + @POST + public FormValidation doCheckVars(@QueryParameter("vars") String vars) { + if (!areValidVars(vars)) { + return FormValidation.error("Vars is invalid"); + } + return FormValidation.ok(); + } + + @Override + public Step newInstance(@Nullable StaplerRequest req, @NonNull JSONObject formData) throws FormException { + String nacosId = formData.getString("nacosId"); + String changeLogFile = formData.getString("changeLogFile"); + Object contexts = formData.getOrDefault("contexts", null); + Object count = formData.getOrDefault("count", null); + Object vars = formData.getOrDefault("vars", null); + NacosChangeSetGetStep step = new NacosChangeSetGetStep(nacosId, null, changeLogFile); + if (Objects.nonNull(contexts) && StringUtils.isNotBlank(contexts.toString())) { + step.setContexts(contexts.toString()); + } + + if (Objects.nonNull(count) && StringUtils.isNotBlank(count.toString())) { + step.setCount(Integer.parseInt(count.toString())); + } + + if (Objects.nonNull(vars)) { + step.setVars(vars.toString()); + } + return step; + } + } + + public static boolean areValidVars(String value) { + String strippedChoices = StringUtils.trim(value); + if (StringUtils.isBlank(strippedChoices)) { + return true; + } + String[] choices = strippedChoices.split(CHOICES_DELIMITER); + if (ArrayUtils.isEmpty(choices)) { + return true; + } + for (String choice : choices) { + String[] pair = choice.split(":"); + if (pair.length != 2) { + return false; + } + } + return true; } } diff --git a/src/main/java/io/jenkins/plugins/configops/nacos/NacosConfigAlterParameterDefinition.java b/src/main/java/io/jenkins/plugins/configops/nacos/NacosConfigAlterParameterDefinition.java index ab8d6d4..612a8b2 100644 --- a/src/main/java/io/jenkins/plugins/configops/nacos/NacosConfigAlterParameterDefinition.java +++ b/src/main/java/io/jenkins/plugins/configops/nacos/NacosConfigAlterParameterDefinition.java @@ -28,6 +28,7 @@ import org.apache.commons.lang.StringUtils; import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.DataBoundSetter; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.bind.JavaScriptMethod; @@ -40,6 +41,7 @@ public class NacosConfigAlterParameterDefinition extends ParameterDefinition { private static final long serialVersionUID = -6182842383814244217L; private List items; + private boolean selectAll = true; @DataBoundConstructor public NacosConfigAlterParameterDefinition(String name, @NonNull List items) { @@ -53,6 +55,11 @@ public NacosConfigAlterParameterDefinition(String name, @NonNull List + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/config.properties b/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/config.properties new file mode 100644 index 0000000..44c6d3e --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/config.properties @@ -0,0 +1,5 @@ +databaseId=DatabaseId +changeLogFile=ChangeLogFile +command=Command +args=Args +cwd=Cwd diff --git a/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help-args.html b/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help-args.html new file mode 100644 index 0000000..73c3b76 --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help-args.html @@ -0,0 +1,4 @@ +
+ The Liquibase command args.https://docs.liquibase.com/commands/command-list.html + . +
diff --git a/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help-changeLogFile.html b/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help-changeLogFile.html new file mode 100644 index 0000000..85f7e2a --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help-changeLogFile.html @@ -0,0 +1,3 @@ +
+ The specified Liquibase change log, can be a file or folder. +
diff --git a/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help-command.html b/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help-command.html new file mode 100644 index 0000000..9aed5c8 --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help-command.html @@ -0,0 +1,4 @@ +
+ The Liquibase command.https://docs.liquibase.com/commands/home.html + . +
diff --git a/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help-cwd.html b/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help-cwd.html new file mode 100644 index 0000000..5719902 --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help-cwd.html @@ -0,0 +1,3 @@ +
+ The Liquibase command is executed in the specified directory. +
diff --git a/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help-databaseId.html b/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help-databaseId.html new file mode 100644 index 0000000..b96471d --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help-databaseId.html @@ -0,0 +1,4 @@ +
+ Database ID configured in the config-ops + configuration file . +
diff --git a/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help.html b/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help.html new file mode 100644 index 0000000..a1d50eb --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/database/LiquibaseRawCmdStep/help.html @@ -0,0 +1,3 @@ +
+

Directly execute the Liquibase command to update the database.

+
diff --git a/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetApplyStep/help.html b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetApplyStep/help.html new file mode 100644 index 0000000..c40b9af --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetApplyStep/help.html @@ -0,0 +1,7 @@ +
+

Apply the nacos change set.

+ + Config parameters please refer to: + NacosChangeSetApplyStep.java + +
diff --git a/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/config.jelly b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/config.jelly new file mode 100644 index 0000000..cc38382 --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/config.jelly @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/config.properties b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/config.properties new file mode 100644 index 0000000..a9d0d25 --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/config.properties @@ -0,0 +1,5 @@ +nacosId=NacosId +changeLogFile=ChangeLogFile +contexts=Contexts +count=Count +vars=Vars diff --git a/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help-changeLogFile.html b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help-changeLogFile.html new file mode 100644 index 0000000..2e0280d --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help-changeLogFile.html @@ -0,0 +1,3 @@ +
+ The specified change log, can be a file or folder. +
diff --git a/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help-contexts.html b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help-contexts.html new file mode 100644 index 0000000..6a51345 --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help-contexts.html @@ -0,0 +1,3 @@ +
+ Only execute the specified contexts of changesets. If not filled, all changesets will be executed by default. +
diff --git a/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help-count.html b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help-count.html new file mode 100644 index 0000000..c5541eb --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help-count.html @@ -0,0 +1,3 @@ +
+ Only execute the specified count of changesets. If not filled, all changesets will be executed by default. +
diff --git a/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help-nacosId.html b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help-nacosId.html new file mode 100644 index 0000000..56fd2dd --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help-nacosId.html @@ -0,0 +1,4 @@ +
+ Nacos ID configured in the config-ops + configuration file . +
diff --git a/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help-vars.html b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help-vars.html new file mode 100644 index 0000000..631cf22 --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help-vars.html @@ -0,0 +1,19 @@ +
+

+ Replace the defined variables in the ChangeLogFile with the values defined by this parameter. +

+

+ The format of the variables in the ChangeLogFile is ${...}. Currently, only namespace, dataId, + and group are supported. +

+ + The format is: [key:value]. + Multiple options are separated by newlines. +

+ Example:
+ + key1:value1
+ key2:value2
+
+

+
diff --git a/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help.html b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help.html new file mode 100644 index 0000000..2fc178a --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosChangeSetGetStep/help.html @@ -0,0 +1,4 @@ +
+

Read the specified Changelog file, obtain the modified Nacos config list, and obtain every current + config value from Nacos.

+
diff --git a/src/main/resources/io/jenkins/plugins/configops/nacos/NacosConfigAlterParameterDefinition/index.jelly b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosConfigAlterParameterDefinition/index.jelly index 896854e..de28a50 100644 --- a/src/main/resources/io/jenkins/plugins/configops/nacos/NacosConfigAlterParameterDefinition/index.jelly +++ b/src/main/resources/io/jenkins/plugins/configops/nacos/NacosConfigAlterParameterDefinition/index.jelly @@ -35,6 +35,7 @@
+ @@ -75,6 +76,7 @@