Skip to content
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
34 changes: 10 additions & 24 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.642.3</version><!-- which version of Jenkins is this plugin built against? Users must have at least this Jenkins version to use this plugin. -->
<version>3.46</version><!-- which version of Jenkins is this plugin built against? Users must have at least this Jenkins version to use this plugin. -->
</parent>

<artifactId>persistent-parameter</artifactId>
<name>Persistent Parameter Plugin</name>
<description>String, text, boolean and choice parameters with default values taken from the previous build (if any).</description>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Persistent+Parameter+Plugin</url>
<version>1.2-SNAPSHOT</version>
<version>1.3-SNAPSHOT</version>
<packaging>hpi</packaging>

<properties>
<jenkins.version>1.651.3</jenkins.version>
<java.level>7</java.level>
<jenkins.version>2.164.1</jenkins.version>
<java.level>8</java.level>
</properties>

<licenses>
Expand All @@ -32,6 +32,11 @@
<name>Gregory E. Moltchadski</name>
<email>[email protected]</email>
</developer>
<developer>
<id>siliconsheep</id>
<name>Dieter Bocklandt</name>
<email>[email protected]</email>
</developer>
</developers>
<scm>
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
Expand All @@ -52,31 +57,12 @@
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>1.15</version>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings-builder</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>1.14</version>
<version>2.33</version>
<type>jar</type>
</dependency>


<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings</artifactId>
<version>3.0.3</version>
</dependency>

</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import hudson.model.ParametersDefinitionProperty;
import net.sf.json.JSONObject;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.Symbol;

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.Stapler;
Expand Down Expand Up @@ -75,12 +76,14 @@ public ParameterDefinition copyWithDefaultValue(ParameterValue defaultValue)
public boolean isDefaultValue()
{
try
{
{
System.out.println("Got Abstract Project");
AbstractProject project = CurrentProject.getCurrentProject(this);
if (project != null) {
AbstractBuild build = (successfulOnly ? (AbstractBuild)project.getLastSuccessfulBuild() : project.getLastBuild());
return Boolean.parseBoolean(build.getBuildVariables().get(getName()).toString());
if (build != null) {
return Boolean.parseBoolean(build.getBuildVariables().get(getName()).toString());
}
}else {
StaplerRequest sr = Stapler.getCurrentRequest();
//System.out.println("Ancestors of current request " +sr.getAncestors());
Expand All @@ -90,11 +93,11 @@ public boolean isDefaultValue()
System.out.println("Trying to fetch lastbuild's Pipeline parameter values only when build is triggered");
WorkflowJob wj = Stapler.getCurrentRequest().findAncestorObject(WorkflowJob.class);
//FlowExecution fe;

System.out.println("Env Vars " + wj.getLastBuild().getEnvVars());
System.out.println(
"PArameter value retrieved is " + wj.getLastBuild().getEnvVars().get(getName()).toString());

return Boolean.parseBoolean(wj.getLastBuild().getEnvVars().get(getName()).toString());
}
}
Expand All @@ -111,15 +114,15 @@ public boolean isDefaultValue()
System.out.println("INTERVAL : Env Vars " + wj.getLastBuild().getEnvVars());
System.out.println(
"INTERVAL :PArameter value retrieved is " + wj.getLastBuild().getEnvVars().get(getName()).toString());

return Boolean.parseBoolean(wj.getLastBuild().getEnvVars().get(getName()).toString());
}

}
}
return defaultValue;
}

public boolean isSuccessfulOnly()
{
return successfulOnly;
Expand All @@ -144,6 +147,7 @@ public BooleanParameterValue getDefaultParameterValue()
return new BooleanParameterValue(getName(), isDefaultValue(), getDescription());
}

@Symbol("persistentBoolean")
@Extension
public static class DescriptorImpl extends ParameterDescriptor
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import hudson.model.StringParameterValue;
import hudson.util.FormValidation;

import org.jenkinsci.Symbol;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -61,8 +63,13 @@ public ParameterDefinition copyWithDefaultValue(ParameterValue defaultValue)
{
if(defaultValue instanceof StringParameterValue)
{
StringParameterValue value = (StringParameterValue)defaultValue;
return new PersistentChoiceParameterDefinition(getName(), getChoices(), value.value, successfulOnly, getDescription());
Object value = ((StringParameterValue) defaultValue).getValue();
return new PersistentChoiceParameterDefinition(
getName(),
getChoices(),
(value != null) ? value.toString() : "",
successfulOnly,
getDescription());
}
else
{
Expand All @@ -78,20 +85,23 @@ public List<String> getChoices()
{
AbstractProject project = CurrentProject.getCurrentProject(this);
AbstractBuild build = (successfulOnly ? (AbstractBuild)project.getLastSuccessfulBuild() : project.getLastBuild());
def = build.getBuildVariables().get(getName()).toString();
if(build != null)
{
def = build.getBuildVariables().get(getName()).toString();
}
}
catch(Exception ex)
{
}

if(def != null && choices.indexOf(def) != 0)
{
List<String> c = new ArrayList<String>(choices);
c.remove(def);
c.add(0, def);
return c;
}

return choices;
}

Expand All @@ -113,8 +123,8 @@ public StringParameterValue getDefaultParameterValue()

private StringParameterValue checkValue(StringParameterValue value)
{
if(!choices.contains(value.value))
throw new IllegalArgumentException("Illegal choice: " + value.value);
if(!choices.contains(value.getValue()))
throw new IllegalArgumentException("Illegal choice: " + value.getValue());
return value;
}

Expand All @@ -131,6 +141,7 @@ public StringParameterValue createValue(String value)
return checkValue(new StringParameterValue(getName(), value, getDescription()));
}

@Symbol("persistentChoice")
@Extension
public static class DescriptorImpl extends ParameterDescriptor
{
Expand Down Expand Up @@ -161,4 +172,4 @@ public FormValidation doCheckChoices(@QueryParameter String value)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
* The MIT License
*
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Luca Domenico Milanesio, Seiji Sogabe, Tom Huybrechts
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -35,6 +35,7 @@
import net.sf.json.JSONObject;
//import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
Expand All @@ -58,8 +59,11 @@ public PersistentStringParameterDefinition(String name, String defaultValue, boo
@Override
public ParameterDefinition copyWithDefaultValue(ParameterValue defaultValue) {
if (defaultValue instanceof StringParameterValue) {
StringParameterValue value = (StringParameterValue) defaultValue;
return new PersistentStringParameterDefinition(getName(), value.value, isSuccessfulOnly(),
Object value = ((StringParameterValue) defaultValue).getValue();
return new PersistentStringParameterDefinition(
getName(),
(value != null) ? value.toString() : "",
isSuccessfulOnly(),
getDescription());
} else {
return this;
Expand All @@ -74,7 +78,9 @@ public String getDefaultValue() {
System.out.println("Got Abstract Project");
AbstractBuild build = (successfulOnly ? (AbstractBuild) project.getLastSuccessfulBuild()
: project.getLastBuild());
return build.getBuildVariables().get(getName()).toString();
if (build != null) {
return build.getBuildVariables().get(getName()).toString();
}
} else {
StaplerRequest sr = Stapler.getCurrentRequest();
//System.out.println("Ancestors of current request " +sr.getAncestors());
Expand All @@ -84,17 +90,17 @@ public String getDefaultValue() {
System.out.println("Trying to fetch lastbuild's Pipeline parameter values only when build is triggered");
WorkflowJob wj = Stapler.getCurrentRequest().findAncestorObject(WorkflowJob.class);
//FlowExecution fe;

System.out.println("Env Vars " + wj.getLastBuild().getEnvVars());
System.out.println(
"PArameter value retrieved is " + wj.getLastBuild().getEnvVars().get(getName()).toString());
"Parameter value retrieved is " + wj.getLastBuild().getEnvVars().get(getName()).toString());

return wj.getLastBuild().getEnvVars().get(getName()).toString();
}
}

} catch (Exception ex) {

for(WorkflowJob wj: Hudson.getInstance().getAllItems(WorkflowJob.class))
{
ParametersDefinitionProperty property = wj.getProperty(ParametersDefinitionProperty.class);
Expand All @@ -105,10 +111,10 @@ public String getDefaultValue() {
System.out.println("INTERVAL : Env Vars " + wj.getLastBuild().getEnvVars());
System.out.println(
"INTERVAL :PArameter value retrieved is " + wj.getLastBuild().getEnvVars().get(getName()).toString());

return wj.getLastBuild().getEnvVars().get(getName()).toString();
}

}
//ex.printStackTrace();
}
Expand Down Expand Up @@ -141,6 +147,7 @@ public ParameterValue createValue(String value) {
return new StringParameterValue(getName(), value, getDescription());
}

@Symbol("persistentString")
@Extension
public static class DescriptorImpl extends ParameterDescriptor {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
* The MIT License
*
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Luca Domenico Milanesio, Seiji Sogabe, Tom Huybrechts
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -28,6 +28,8 @@
import hudson.model.TextParameterValue;
import net.sf.json.JSONObject;

import org.jenkinsci.Symbol;

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

Expand All @@ -45,6 +47,7 @@ public PersistentTextParameterDefinition(String name, String defaultValue, boole
super(name, defaultValue, successfulOnly, description);
}

@Symbol("persistentText")
@Extension
public static class DescriptorImpl extends ParameterDescriptor
{
Expand Down