Skip to content

Commit

Permalink
first addition to expose scripts via git (JENKINS-15276)
Browse files Browse the repository at this point in the history
  • Loading branch information
imod committed Oct 11, 2012
1 parent 2366ed8 commit d76a4f2
Show file tree
Hide file tree
Showing 9 changed files with 402 additions and 178 deletions.
284 changes: 149 additions & 135 deletions pom.xml
Expand Up @@ -7,139 +7,153 @@
<!-- <version>1.460</version> version caused JENKINS-13518 -->
</parent>

<artifactId>scriptler</artifactId>
<name>Scriptler</name>
<version>2.5-SNAPSHOT</version>
<packaging>hpi</packaging>
<description>Scriptler allows you to store/edit/execute groovy scripts on any of the slaves/nodes... no need to copy paste groovy code anymore. Beside administer your scripts, Scritpler also provides a way to share scripts between users via hosted script catalogs on the internet.</description>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Scriptler+Plugin</url>
<inceptionYear>2010</inceptionYear>
<developers>
<developer>
<id>imod</id>
<name>Dominik Bartholdi</name>
<email>-</email>
</developer>
</developers>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.cloudbees</groupId>
<artifactId>maven-license-plugin</artifactId>
<version>1.7</version>
</plugin>
<plugin>
<groupId>org.kohsuke</groupId>
<artifactId>access-modifier-checker</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<groupId>org.jvnet.localizer</groupId>
<artifactId>maven-localizer-plugin</artifactId>
<version>1.14</version>
</plugin>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>display-info</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<versionRange>[1.3,)</versionRange>
<goals>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<version>1.90</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
<configuration>
<goals>deploy</goals>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<scm>
<connection>scm:git:git://github.com/jenkinsci/scriptler-plugin.git</connection>
<developerConnection>scm:git:ssh://git@github.com/jenkinsci/scriptler-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/scriptler-plugin</url>
</scm>
<distributionManagement>
<repository>
<id>java.net-m2-repository</id>
<url>http://maven.jenkins-ci.org:8081/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<!-- prevent accidental deployment of SNAPSHOTS to repository -->
<id>local.repository</id>
<url>file:/tmp/dummy-repo</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>token-macro</artifactId>
<version>1.5.1</version>
</dependency>
</dependencies>
<artifactId>scriptler</artifactId>
<name>Scriptler</name>
<version>2.5-SNAPSHOT</version>
<packaging>hpi</packaging>
<description>Scriptler allows you to store/edit/execute groovy scripts on any of the slaves/nodes... no need to copy paste groovy code anymore. Beside administer your scripts, Scritpler also provides a way to share scripts between users via hosted script catalogs on the internet.</description>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Scriptler+Plugin</url>
<inceptionYear>2010</inceptionYear>
<developers>
<developer>
<id>imod</id>
<name>Dominik Bartholdi</name>
<email>-</email>
</developer>
</developers>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.cloudbees</groupId>
<artifactId>maven-license-plugin</artifactId>
<version>1.7</version>
</plugin>
<plugin>
<groupId>org.kohsuke</groupId>
<artifactId>access-modifier-checker</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<groupId>org.jvnet.localizer</groupId>
<artifactId>maven-localizer-plugin</artifactId>
<version>1.14</version>
</plugin>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>display-info</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<versionRange>[1.3,)</versionRange>
<goals>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<version>1.90</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
<configuration>
<goals>deploy</goals>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<scm>
<connection>scm:git:git://github.com/jenkinsci/scriptler-plugin.git</connection>
<developerConnection>scm:git:ssh://git@github.com/jenkinsci/scriptler-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/scriptler-plugin</url>
</scm>
<distributionManagement>
<repository>
<id>java.net-m2-repository</id>
<url>http://maven.jenkins-ci.org:8081/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<!-- prevent accidental deployment of SNAPSHOTS to repository -->
<id>local.repository</id>
<url>file:/tmp/dummy-repo</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>token-macro</artifactId>
<version>1.5.1</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.modules</groupId>
<artifactId>sshd</artifactId>
<version>1.1</version>
<!-- <scope>provided</scope>this is in the core -->
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git-server</artifactId>
<version>1.1</version>
<optional>true</optional>
</dependency>
</dependencies>
</project>
Expand Up @@ -155,9 +155,8 @@ public String getPluginResourcePath() {
* @return
* @throws IOException
*/
public HttpResponse doScriptlerSettings(StaplerRequest res, StaplerResponse rsp, @QueryParameter("disableRemoteCatalog") boolean disableRemoteCatalog,
@QueryParameter("allowRunScriptPermission") boolean allowRunScriptPermission, @QueryParameter("allowRunScriptEdit") boolean allowRunScriptEdit)
throws IOException {
public HttpResponse doScriptlerSettings(StaplerRequest res, StaplerResponse rsp, @QueryParameter("disableRemoteCatalog") boolean disableRemoteCatalog, @QueryParameter("allowRunScriptPermission") boolean allowRunScriptPermission,
@QueryParameter("allowRunScriptEdit") boolean allowRunScriptEdit) throws IOException {
checkPermission(Hudson.ADMINISTER);

ScriptlerConfiguration cfg = getConfiguration();
Expand All @@ -184,8 +183,7 @@ public HttpResponse doScriptlerSettings(StaplerRequest res, StaplerResponse rsp,
* @throws IOException
* @throws ServletException
*/
public HttpResponse doDownloadScript(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id") String id, @QueryParameter("catalog") String catalogName)
throws IOException, ServletException {
public HttpResponse doDownloadScript(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id") String id, @QueryParameter("catalog") String catalogName) throws IOException, ServletException {
checkPermission(Hudson.ADMINISTER);

ScriptlerConfiguration c = getConfiguration();
Expand Down Expand Up @@ -237,8 +235,7 @@ public HttpResponse doDownloadScript(StaplerRequest req, StaplerResponse rsp, @Q
* @throws IOException
* @throws ServletException
*/
public HttpResponse doScriptAdd(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id") String id, @QueryParameter("name") String name,
@QueryParameter("comment") String comment, @QueryParameter("script") String script,
public HttpResponse doScriptAdd(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id") String id, @QueryParameter("name") String name, @QueryParameter("comment") String comment, @QueryParameter("script") String script,
@QueryParameter("nonAdministerUsing") boolean nonAdministerUsing, @QueryParameter("onlyMaster") boolean onlyMaster, String originCatalogName, String originId) throws IOException, ServletException {

checkPermission(Hudson.ADMINISTER);
Expand All @@ -255,8 +252,7 @@ public HttpResponse doScriptAdd(StaplerRequest req, StaplerResponse rsp, @QueryP
* @return the final name of the saved script - which is also the id of the script!
* @throws IOException
*/
private String saveScriptAndForward(String id, String name, String comment, String script, boolean nonAdministerUsing, boolean onlyMaster, String originCatalogName,
String originId, Parameter[] parameters) throws IOException {
private String saveScriptAndForward(String id, String name, String comment, String script, boolean nonAdministerUsing, boolean onlyMaster, String originCatalogName, String originId, Parameter[] parameters) throws IOException {
script = script == null ? "TODO" : script;
if (StringUtils.isEmpty(id)) {
throw new IllegalArgumentException("'id' must not be empty!");
Expand All @@ -273,11 +269,10 @@ private String saveScriptAndForward(String id, String name, String comment, Stri

Script newScript = null;
if (!StringUtils.isEmpty(originId)) {
newScript = new Script(finalFileName, displayName, comment, true, originCatalogName, originId,
new SimpleDateFormat("dd MMM yyyy HH:mm:ss a").format(new Date()), parameters);
newScript = new Script(finalFileName, displayName, comment, true, originCatalogName, originId, new SimpleDateFormat("dd MMM yyyy HH:mm:ss a").format(new Date()), parameters);
} else {
// save (overwrite) the meta information
newScript = new Script(finalFileName, displayName, comment, nonAdministerUsing, parameters, onlyMaster);
newScript = new Script(finalFileName, displayName, comment, nonAdministerUsing, parameters, onlyMaster, null);
}
ScriptlerConfiguration cfg = getConfiguration();
cfg.addOrReplace(newScript);
Expand Down Expand Up @@ -397,8 +392,7 @@ public void doRunScript(StaplerRequest req, StaplerResponse rsp, @QueryParameter
* @throws IOException
* @throws ServletException
*/
public void doTriggerScript(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id") String id, @QueryParameter("script") String scriptSrc,
@QueryParameter("node") String node) throws IOException, ServletException {
public void doTriggerScript(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id") String id, @QueryParameter("script") String scriptSrc, @QueryParameter("node") String node) throws IOException, ServletException {

checkPermission(getRequiredPermissionForRunScript());

Expand Down Expand Up @@ -495,8 +489,8 @@ public void doEditScript(StaplerRequest req, StaplerResponse rsp, @QueryParamete
* @return list with all slave names
*/
public List<String> getSlaveAlias(Script script) {
if(script.onlyMaster){

if (script.onlyMaster) {
List<String> slaveNames = new ArrayList<String>();
slaveNames.add(MASTER);
return slaveNames;
Expand Down Expand Up @@ -569,6 +563,10 @@ public static File getScriptDirectory() {
return new File(getScriptlerHomeDirectory(), "scripts");
}

public static File getGitScriptDirectory() {
return new File(getScriptlerHomeDirectory(), "gitrepo");
}

public static File getScriptlerHomeDirectory() {
return new File(Hudson.getInstance().getRootDir(), "scriptler");
}
Expand Down

0 comments on commit d76a4f2

Please sign in to comment.