-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: apply code formatting using spotless
- Loading branch information
kun.tang
committed
Oct 13, 2024
1 parent
879246b
commit ad96c2c
Showing
9 changed files
with
153 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,106 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>plugin</artifactId> | ||
<version>4.85</version> | ||
<relativePath/> | ||
</parent> | ||
<parent> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>plugin</artifactId> | ||
<version>4.85</version> | ||
<relativePath /> | ||
</parent> | ||
|
||
<groupId>io.jenkins.plugins</groupId> | ||
<artifactId>environment-variables-status-sync</artifactId> | ||
<version>${revision}</version> | ||
<packaging>hpi</packaging> | ||
<groupId>io.jenkins.plugins</groupId> | ||
<artifactId>environment-variables-status-sync</artifactId> | ||
<version>${revision}${changelist}</version> | ||
<packaging>hpi</packaging> | ||
|
||
<name>Job Environment Variables Status Sync</name> | ||
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url> | ||
<description>Empowers third-party systems to seamlessly access real-time environment variables and execution status of Jenkins jobs.</description> | ||
<licenses> | ||
<license> | ||
<name>MIT License</name> | ||
<url>https://opensource.org/license/mit/</url> | ||
</license> | ||
</licenses> | ||
<developers> | ||
<developer> | ||
<id>thomson</id> | ||
<name>kun.tang</name> | ||
<email>[email protected]</email> | ||
</developer> | ||
</developers> | ||
<scm child.scm.connection.inherit.append.path="false" child.scm.developerConnection.inherit.append.path="false" | ||
child.scm.url.inherit.append.path="false"> | ||
<connection>scm:git:https://github.com/kun303-cloud/job-status-listener</connection> | ||
<developerConnection>scm:git:https://github.com/kun303-cloud/job-status-listener.git</developerConnection> | ||
<tag>main</tag> | ||
<url>https://github.com/kun303-cloud/job-status-listener</url> | ||
</scm> | ||
<name>Job Environment Variables Status Sync</name> | ||
<description>Empowers third-party systems to seamlessly access real-time environment variables and execution status of Jenkins jobs.</description> | ||
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url> | ||
<licenses> | ||
<license> | ||
<name>MIT License</name> | ||
<url>https://opensource.org/license/mit/</url> | ||
</license> | ||
</licenses> | ||
<developers> | ||
<developer> | ||
<id>thomson</id> | ||
<name>kun.tang</name> | ||
<email>[email protected]</email> | ||
</developer> | ||
</developers> | ||
<scm child.scm.connection.inherit.append.path="false" child.scm.developerConnection.inherit.append.path="false" child.scm.url.inherit.append.path="false"> | ||
<connection>scm:git:https://github.com/${gitHubRepo}</connection> | ||
<developerConnection>scm:git:https://github.com/${gitHubRepo}</developerConnection> | ||
<tag>${scmTag}</tag> | ||
<url>https://github.com/${gitHubRepo}</url> | ||
</scm> | ||
|
||
<properties> | ||
<revision>1.07</revision> | ||
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ --> | ||
<jenkins.version>2.440.3</jenkins.version> | ||
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo> | ||
<properties> | ||
<revision>2.0.0</revision> | ||
<changelist>-SNAPSHOT</changelist> | ||
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ --> | ||
<jenkins.version>2.440.3</jenkins.version> | ||
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo> | ||
|
||
<spotless.check.skip>false</spotless.check.skip> | ||
<fastjson2.version>2.0.51</fastjson2.version> | ||
</properties> | ||
<spotless.check.skip>false</spotless.check.skip> | ||
<fastjson2.version>2.0.51</fastjson2.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.jenkins.tools.bom</groupId> | ||
<artifactId>bom-2.440.x</artifactId> | ||
<version>3193.v330d8248d39e</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<version>2.0.20</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.34</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba.fastjson2</groupId> | ||
<artifactId>fastjson2</artifactId> | ||
<version>${fastjson2.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.jenkins.plugins</groupId> | ||
<artifactId>okhttp-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba.fastjson2</groupId> | ||
<artifactId>fastjson2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.jenkins.tools.bom</groupId> | ||
<artifactId>bom-2.440.x</artifactId> | ||
<version>3193.v330d8248d39e</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba.fastjson2</groupId> | ||
<artifactId>fastjson2</artifactId> | ||
<version>${fastjson2.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<version>2.0.20</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.34</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.alibaba.fastjson2</groupId> | ||
<artifactId>fastjson2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.jenkins.plugins</groupId> | ||
<artifactId>okhttp-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<repositories> | ||
<repository> | ||
<id>repo.jenkins-ci.org</id> | ||
<url>https://repo.jenkins-ci.org/public/</url> | ||
</repository> | ||
</repositories> | ||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>repo.jenkins-ci.org</id> | ||
<url>https://repo.jenkins-ci.org/public/</url> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
<repositories> | ||
<repository> | ||
<id>repo.jenkins-ci.org</id> | ||
<url>https://repo.jenkins-ci.org/public/</url> | ||
</repository> | ||
</repositories> | ||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>repo.jenkins-ci.org</id> | ||
<url>https://repo.jenkins-ci.org/public/</url> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package io.jenkins.plugins.env_variables_status_sync; | ||
|
||
import static io.jenkins.plugins.env_variables_status_sync.utils.Utils.getEnvVars; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.EnvVars; | ||
import hudson.Extension; | ||
|
@@ -10,9 +12,6 @@ | |
import io.jenkins.plugins.env_variables_status_sync.utils.HttpClient; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import static io.jenkins.plugins.env_variables_status_sync.utils.Utils.getEnvVars; | ||
|
||
|
||
/** | ||
* Author: [email protected] | ||
* Date:2024/9/13 | ||
|
@@ -24,26 +23,22 @@ public class JobRunListener extends RunListener<Run<?, ?>> { | |
|
||
@Override | ||
public void onCompleted(Run<?, ?> run, @NonNull TaskListener listener) { | ||
sendStatus(run, listener,JobStatus.COMPLETE); | ||
sendStatus(run, listener, JobStatus.COMPLETE); | ||
} | ||
|
||
@Override | ||
public void onStarted(Run<?, ?> run, TaskListener listener) { | ||
sendStatus(run, listener,JobStatus.START); | ||
sendStatus(run, listener, JobStatus.START); | ||
} | ||
|
||
|
||
|
||
private static void sendStatus(Run<?, ?> run, TaskListener listener, JobStatus jobStatus) { | ||
try { | ||
log.info("Pipeline Status Notification job status : {} ",jobStatus); | ||
EnvVars vars = getEnvVars(run, listener,jobStatus); | ||
log.info("Pipeline Status Notification send values : {}",vars); | ||
log.info("Pipeline Status Notification job status : {} ", jobStatus); | ||
EnvVars vars = getEnvVars(run, listener, jobStatus); | ||
log.info("Pipeline Status Notification send values : {}", vars); | ||
HttpClient.executeRequest(vars); | ||
} catch (Exception e) { | ||
listener.getLogger().println("Pipeline Status Notification send job status error:"+e.getMessage()); | ||
listener.getLogger().println("Pipeline Status Notification send job status error:" + e.getMessage()); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,28 @@ | ||
package io.jenkins.plugins.env_variables_status_sync; | ||
|
||
import static io.jenkins.plugins.env_variables_status_sync.enums.Constants.*; | ||
import static io.jenkins.plugins.env_variables_status_sync.utils.Utils.encoderPassword; | ||
|
||
import hudson.BulkChange; | ||
import hudson.Extension; | ||
import hudson.util.ListBoxModel; | ||
import io.jenkins.plugins.Messages; | ||
import io.jenkins.plugins.env_variables_status_sync.enums.HttpMethod; | ||
import io.jenkins.plugins.env_variables_status_sync.model.HttpHeader; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import jenkins.model.GlobalConfiguration; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.sf.json.JSONObject; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static io.jenkins.plugins.env_variables_status_sync.enums.Constants.*; | ||
import static io.jenkins.plugins.env_variables_status_sync.utils.Utils.encoderPassword; | ||
|
||
/** | ||
* Author: [email protected] | ||
* Date:2024/9/14 | ||
* Time:11:41 | ||
*/ | ||
|
||
|
||
@Getter | ||
@Extension | ||
@ToString | ||
|
@@ -42,7 +39,6 @@ public JobRunListenerSysConfig() { | |
|
||
private HttpMethod requestMethod; | ||
|
||
|
||
@Override | ||
public boolean configure(StaplerRequest req, JSONObject json) { | ||
try (BulkChange bc = new BulkChange(this)) { | ||
|
@@ -53,8 +49,8 @@ public boolean configure(StaplerRequest req, JSONObject json) { | |
String httpMethod = json.getString(FORM_KEY_REQUEST_METHOD); | ||
setRequestMethod(HttpMethod.valueOf(httpMethod)); | ||
bc.commit(); | ||
}catch (IOException e){ | ||
throw new IllegalArgumentException(Messages.JobRunListenerSysConfig_abort_errors()); | ||
} catch (IOException e) { | ||
throw new IllegalArgumentException(Messages.JobRunListenerSysConfig_abort_errors()); | ||
} | ||
return true; | ||
} | ||
|
@@ -78,13 +74,12 @@ public void setRequestMethod(HttpMethod requestMethod) { | |
public ListBoxModel doFillHttpMethodItems() { | ||
ListBoxModel items = new ListBoxModel(); | ||
if (requestMethod == null) { | ||
requestMethod = HttpMethod.POST; // 默认选择 POST 方法 | ||
requestMethod = HttpMethod.POST; // 默认选择 POST 方法 | ||
} | ||
for (HttpMethod method : HttpMethod.values()) { | ||
boolean isSelected = method.name().equals(requestMethod.name()); | ||
items.add(new ListBoxModel.Option(method.name(), method.name(), isSelected)); | ||
} | ||
return items; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package io.jenkins.plugins.env_variables_status_sync; | ||
|
||
import static io.jenkins.plugins.env_variables_status_sync.enums.Constants.NOTIFY_CONTENT; | ||
import static io.jenkins.plugins.env_variables_status_sync.enums.Constants.STEP_NAME; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.EnvVars; | ||
import hudson.Extension; | ||
|
@@ -14,18 +17,13 @@ | |
import io.jenkins.plugins.env_variables_status_sync.enums.JobStatus; | ||
import io.jenkins.plugins.env_variables_status_sync.utils.HttpClient; | ||
import io.jenkins.plugins.env_variables_status_sync.utils.Utils; | ||
import jenkins.model.Jenkins; | ||
import java.io.IOException; | ||
import jenkins.tasks.SimpleBuildStep; | ||
import lombok.Data; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.jenkinsci.Symbol; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import java.io.IOException; | ||
|
||
import static io.jenkins.plugins.env_variables_status_sync.enums.Constants.NOTIFY_CONTENT; | ||
import static io.jenkins.plugins.env_variables_status_sync.enums.Constants.STEP_NAME; | ||
|
||
/** | ||
* Author: [email protected] | ||
* Date:2024/9/18 | ||
|
@@ -43,19 +41,24 @@ public NotificationStep(String body) { | |
} | ||
|
||
@Override | ||
public void perform(@NonNull Run<?, ?> run, @NonNull FilePath workspace, @NonNull EnvVars env, @NonNull Launcher launcher, @NonNull TaskListener listener) throws InterruptedException, IOException { | ||
public void perform( | ||
@NonNull Run<?, ?> run, | ||
@NonNull FilePath workspace, | ||
@NonNull EnvVars env, | ||
@NonNull Launcher launcher, | ||
@NonNull TaskListener listener) | ||
throws InterruptedException, IOException { | ||
var envVar = Utils.getEnvVars(run, listener, JobStatus.RUNNING); | ||
envVar.put(NOTIFY_CONTENT, body); | ||
log.info("Pipeline Status Notification send notify values : {}",envVar); | ||
log.info("Pipeline Status Notification send notify values : {}", envVar); | ||
try { | ||
|
||
HttpClient.executeRequest(envVar); | ||
} catch (Exception e) { | ||
listener.getLogger().println("Pipeline Status Notification send notify error : "+e.getMessage()); | ||
listener.getLogger().println("Pipeline Status Notification send notify error : " + e.getMessage()); | ||
} | ||
} | ||
|
||
|
||
@Symbol(STEP_NAME) | ||
@Extension | ||
public static final class DescriptorImpl extends BuildStepDescriptor<Builder> { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.