Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-9126] added 'set-build-displayname' CLI command.
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 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
47 changes: 47 additions & 0 deletions
47
core/src/main/java/hudson/cli/SetBuildDisplayNameCommand.java
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package hudson.cli; | ||
|
||
import hudson.Extension; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.Run; | ||
import hudson.remoting.Callable; | ||
import org.apache.commons.io.IOUtils; | ||
import org.kohsuke.args4j.Argument; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
|
||
@Extension | ||
public class SetBuildDisplayNameCommand extends CLICommand implements Serializable { | ||
|
||
@Override | ||
public String getShortDescription() { | ||
return "Sets the displayName of a build"; | ||
} | ||
|
||
@Argument(metaVar="JOB", usage="Name of the job to build", required=true, index=0) | ||
public transient AbstractProject<?, ?> job; | ||
|
||
@Argument(metaVar="BUILD#", usage="Number of the build", required=true, index=1) | ||
public int number; | ||
|
||
@Argument(metaVar="DISPLAYNAME", required=true, usage="DisplayName to be set. '-' to read from stdin.", index=2) | ||
public String displayName; | ||
|
||
protected int run() throws Exception { | ||
Run run = job.getBuildByNumber(number); | ||
run.checkPermission(Run.UPDATE); | ||
|
||
if ("-".equals(displayName)) { | ||
displayName = channel.call(new Callable<String, IOException>() { | ||
public String call() throws IOException { | ||
return IOUtils.toString(System.in); | ||
} | ||
}); | ||
} | ||
|
||
run.setDisplayName(displayName); | ||
|
||
return 0; | ||
} | ||
|
||
} |