Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete component option added #184

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Jenkins Environment Dashboard Plugin
=========================


This Jenkins plugin creates a custom view which can be used as a dashboard to display what code release versions have been deployed to what test and production environments (or devices).

![JobConfig](https://github.com/vipinsthename/environment-dashboard/raw/master/img/config.png)
Expand Down Expand Up @@ -105,4 +106,4 @@ environmentDashboard(addColumns: true, buildJob: '', buildNumber: 'Version-1', c
// some block
}

```
```
138 changes: 63 additions & 75 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,77 +1,65 @@
<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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.15</version>
<relativePath />
</parent>

<groupId>io.jenkins.plugins</groupId>
<artifactId>environment-dashboard</artifactId>
<version>${revision}${changelist}</version>
<packaging>hpi</packaging>
<name>Environment Dashboard Plugin</name>
<url>https://github.com/jenkinsci/environment-dashboard-plugin</url>

<licenses>
<license>
<name>MIT License</name>
<url>https://opensource.org/licenses/MIT</url>
</license>
</licenses>

<developers>
<developer>
<id>vipinsthename</id>
<name>Vipin</name>
<email>[email protected]</email>
</developer>
<developer>
<id>willwh</id>
<name>William Hetherington</name>
<email>[email protected]</email>
</developer>
</developers>

<scm>
<connection>scm:git:[email protected]:${gitHubRepo}.git</connection>
<developerConnection>scm:git:[email protected]:${gitHubRepo}.git</developerConnection>
<url>https://github.com/${gitHubRepo}</url>
<tag>${scmTag}</tag>
</scm>

<properties>
<revision>1.1.11</revision>
<changelist>-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/environment-dashboard-plugin</gitHubRepo>
<jenkins.version>2.223</jenkins.version>
<java.level>8</java.level>
<spotbugs.failOnError>false</spotbugs.failOnError>
</properties>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>job-dsl</artifactId>
<version>1.76</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<!-- TODO once baseline is 2.249.x or greater then remove this version and pull from Jenkins core bom (versions must be in sync) -->
<version>2.4.12</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jquery</artifactId>
<version>1.12.4-1</version>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.15</version>
<relativePath />
</parent>
<groupId>io.jenkins.plugins</groupId>
<artifactId>environment-dashboard</artifactId>
<version>${revision}${changelist}</version>
<packaging>hpi</packaging>
<name>Environment Dashboard Plugin</name>
<url>https://github.com/jenkinsci/environment-dashboard-plugin</url>
<licenses>
<license>
<name>MIT License</name>
<url>https://opensource.org/licenses/MIT</url>
</license>
</licenses>
<scm>
<connection>scm:git:[email protected]:${gitHubRepo}.git</connection>
<developerConnection>scm:git:[email protected]:${gitHubRepo}.git</developerConnection>
<url>https://github.com/${gitHubRepo}</url>
<tag>${scmTag}</tag>
</scm>
<repositories>
<repository>
<id>maven.jenkins-ci.org</id>
<name>jenkinsci-releases</name>
<url>https://repo.jenkins-ci.org/releases</url>
</repository>
</repositories>
<properties>
<revision>1.1.11</revision>
<changelist>-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/environment-dashboard-plugin</gitHubRepo>
<jenkins.version>2.223</jenkins.version>
<java.level>8</java.level>
<spotbugs.failOnError>false</spotbugs.failOnError>
</properties>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>job-dsl</artifactId>
<version>1.76</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<!-- TODO once baseline is 2.249.x or greater then remove this version and pull from Jenkins core bom (versions must be in sync) -->
<version>2.4.12</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jquery</artifactId>
<version>1.12.4-1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
Expand All @@ -20,6 +21,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Objects;

import javax.servlet.ServletException;

Expand Down Expand Up @@ -47,14 +49,17 @@ public class EnvDashboardView extends View {
private String compOrder = null;

private String deployHistory = null;

private String componentNameWillBeDeleted = null;

@DataBoundConstructor
public EnvDashboardView(final String name, final String envOrder, final String compOrder,
final String deployHistory) {
final String deployHistory, final String componentNameWillBeDeleted) {
super(name, Hudson.getInstance());
this.envOrder = envOrder;
this.compOrder = compOrder;
this.deployHistory = deployHistory;
this.componentNameWillBeDeleted = componentNameWillBeDeleted;
}

static {
Expand Down Expand Up @@ -108,6 +113,35 @@ public void doPurgeSubmit(final StaplerRequest req, StaplerResponse res)
res.forwardToPreviousPage(req);
}

@RequirePOST
public void doDeleteComponent(final StaplerRequest req, StaplerResponse res)
throws IOException, ServletException, FormException {
checkPermission(Jenkins.ADMINISTER);
//System.out.println("[OKSY_log value of componentNameWillBeDeleted in doDeleteComponent method: ]" + componentNameWillBeDeleted);
String runQuery = null;
runQuery = "DELETE FROM env_dashboard where compName = ?;";

try (Connection conn = DBConnection.getConnection();
PreparedStatement preStat = Objects.nonNull(conn) ? conn.prepareStatement(runQuery) : null;) {

if (Objects.nonNull(preStat)) {
preStat.setString(1, componentNameWillBeDeleted);
preStat.executeUpdate();

System.out.println("Selected component has been removed successfully!.. " + componentNameWillBeDeleted);
}else{
System.err.println("Empty connection");
}




} catch (SQLException e) {
System.out.println("E15: Could not delete component lines.\n" + e.getMessage());
}
res.forwardToPreviousPage(req);
}

@Override
public Item doCreateItem(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
return Hudson.getInstance().doCreateItem(req, rsp);
Expand All @@ -119,6 +153,7 @@ public static final class DescriptorImpl extends ViewDescriptor {
private String envOrder;
private String compOrder;
private String deployHistory;
//private String componentNameWillBeDeleted;

/**
* descriptor impl constructor This empty constructor is required for
Expand Down Expand Up @@ -233,6 +268,7 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
envOrder = formData.getString("envOrder");
compOrder = formData.getString("compOrder");
deployHistory = formData.getString("deployHistory");
//componentNameWillBeDeleted = formData.getString("componentNameWillBeDeleted");
save();
return super.configure(req, formData);
}
Expand Down Expand Up @@ -519,6 +555,14 @@ public void setDeployHistory(final String deployHistory) {
this.deployHistory = deployHistory;
}

public String getcomponentNameWillBeDeleted() {
return componentNameWillBeDeleted;
}

public void setcomponentNameWillBeDeleted(final String componentNameWillBeDeleted) {
this.componentNameWillBeDeleted = componentNameWillBeDeleted;
}

@Override
public boolean contains(TopLevelItem topLevelItem) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<f:textbox default="10"/>
</f:entry>

<f:entry title="Component name which will be deleted" field="componentNameWillBeDeleted">
<f:textbox default="myeDefault"/>
</f:entry>

<j:if test="${h.hasPermission(app.ADMINISTER)}">
<f:advanced>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
</f:advanced>
</f:form>
</j:if>
<j:if test="${h.hasPermission(app.ADMINISTER)}">
<f:form name="deleteComponent" method="post" action="deleteComponent" tableClass="advancedLink">

<f:advanced title="${%Delete Component Line}">
<f:entry>
<input type="submit" name="Submit" value="${%Delete Component}" class="submit-button danger" />
</f:entry>
</f:advanced>
</f:form>
</j:if>
</l:main-panel>
</l:layout>
</j:jelly>