Skip to content

Commit

Permalink
Updates to generate version information in the pipeline script, print…
Browse files Browse the repository at this point in the history
… it out, and also print out version information for the VectorcASTSetup setup while the plugin runs.
  • Loading branch information
TimSVector committed Mar 26, 2020
1 parent b414e1b commit 583a0a3
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,33 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.FileReader;
import java.io.PrintStream;
import java.io.IOException;
import java.io.File;
import java.util.List;
import org.apache.commons.io.FileUtils;


import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.Map;
import java.util.jar.Manifest;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Attributes;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.tasks.SimpleBuildStep;
import org.apache.commons.io.FileUtils;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

/**
* VectorCAST setup build action
*/
Expand Down Expand Up @@ -429,6 +446,33 @@ private void processDir(File dir, String base, FilePath destDir, Boolean directD
}
}
}

public void printVersion(TaskListener listener, JarFile jFile) {

String path = null;


final PrintStream logger = listener.getLogger();
String Version = "Unknown";

try {
path = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
path = URLDecoder.decode(path, "utf-8");

File testPath = new File(path);
JarFile jarfile = new JarFile(testPath);

Manifest manifest = jarfile.getManifest(); //jFile.getManifest();

Attributes attrib = manifest.getMainAttributes();
Version = attrib.getValue("Plugin-Version");

} catch (IOException e) {
e.printStackTrace();
logger.println("[VectorCAST Execution printVersion error]" + e);
}
logger.println("[VectorCAST Execution Version]: " + Version);
}
/**
* Perform the build step. Copy the scripts from the archive/directory to the workspace
* @param build build
Expand Down Expand Up @@ -459,9 +503,12 @@ public void perform(Run<?,?> build, FilePath workspace, Launcher launcher, TaskL
if (testPath.isFile()) {
// Have jar file...
jFile = new JarFile(testPath);
printVersion(listener, jFile);
Enumeration<JarEntry> entries = jFile.entries();

while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();

if (entry.getName().startsWith("scripts")) {
String fileOrDir = entry.getName().substring(8); // length of scripts/
FilePath dest = new FilePath(destScriptDir, fileOrDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.net.URLDecoder;
import java.util.jar.Manifest;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Attributes;


/**
Expand Down Expand Up @@ -329,6 +334,38 @@ private String getBaseJenkinsfile() throws IOException {
* @return script portion of pipeline job.
* @throws IOException
*/
public String getVersion() {

String path = null;

String Version = "Unknown";

try {
path = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
path = URLDecoder.decode(path, "utf-8");

File testPath = new File(path);
JarFile jarfile = new JarFile(testPath);

Manifest manifest = jarfile.getManifest(); //jFile.getManifest();

Attributes attrib = manifest.getMainAttributes();
Version = attrib.getValue("Plugin-Version");

} catch (IOException e) {
e.printStackTrace();
}

return Version;
}
/**
* Generates the <script> portion of the config.xml which defines the pipeline.
* for this pipeline job.
*
*
* @return script portion of pipeline job.
* @throws IOException
*/

private String generateJenkinsfile() throws IOException {
String setup = "";
Expand Down Expand Up @@ -366,6 +403,7 @@ private String generateJenkinsfile() throws IOException {
"VC_waitTime = '" + getWaitTime() + "'\n" +
"VC_waitLoops = '" + getWaitLoops() + "'\n" +
"VC_useOneCheckoutDir = " + singleCheckout + "\n" +
"VC_createdWithVersion = '" + getVersion() + "'\n" +
"\n" +
"\n" +
"/* DEBUG JSON RESPONSE: \n" + debugJSON + "\n*/"+
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/scripts/baseJenkinsfile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def transformIntoStep(inputString) {
// Run the setup step to copy over the scripts
step([$class: 'VectorCASTSetup'])


if (VC_usingSCM && !VC_useOneCheckoutDir) {
// set options for each manage project pulled out out of SCM
setupManageProject()
Expand Down Expand Up @@ -261,6 +262,8 @@ pipeline {
scmStep()
}

println "Created with VectorCAST Execution Version: " + VC_createdWithVersion

// Run the setup step to copy over the scripts
step([$class: 'VectorCASTSetup'])

Expand Down

0 comments on commit 583a0a3

Please sign in to comment.