Skip to content

Commit

Permalink
Merge pull request #11 from jenkinsci/tms-pipeline-FB90016-FB90046-FB…
Browse files Browse the repository at this point in the history
…89749-FB90015-FB90046

Tms pipeline fb90016 fb90046 fb89749 fb90015 fb90046
  • Loading branch information
nbelliot committed Apr 10, 2020
2 parents 77cfe0d + e982e12 commit b7d68e8
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 190 deletions.
178 changes: 0 additions & 178 deletions Changes.txt

This file was deleted.

9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ There are 2 options for running tests
results from all these individual machines/nodes
- In this case, the VectorCAST/Manage project should be specified
as relative to the root of the checkout
- There is now an option for the user can choose to use the main Pipeline Job's Workspace as
- There is now an option to use the main Pipeline Job's Workspace as
a dedicated single checkout directory. This checkout directory must be available
to all executors across all nodes either by having all executors running on the same
computer or have the main Pipeline Job's Workspace on a shared network drive.
Expand Down Expand Up @@ -191,6 +191,13 @@ The current pipeline implementation will not work in a multi-branch pipeline job

## Changelog

### Version 0.63 (8 April 2020)

- Support Multi-Branch Pipelines
- Include plugin version in Pipeline Job Jenkins Script and console log
- Check for illegal characters in Pipeline Job names
- Update Single Jobs to use same reporting as Pipeline Jobs

### Version 0.62 (10 March 2020)

- Introduce pipeline job
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package com.vectorcast.plugins.vectorcastexecution;

import com.vectorcast.plugins.vectorcastexecution.common.VcastUtils;

import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
Expand All @@ -36,6 +38,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.jar.JarEntry;
Expand Down Expand Up @@ -429,6 +432,12 @@ private void processDir(File dir, String base, FilePath destDir, Boolean directD
}
}
}

private void printVersion( PrintStream logger )
{
logger.println( "[VectorCAST Execution Version]: " + VcastUtils.getVersion().orElse( "Error - Could not determine version" ) );
}

/**
* Perform the build step. Copy the scripts from the archive/directory to the workspace
* @param build build
Expand Down Expand Up @@ -459,6 +468,7 @@ public void perform(Run<?,?> build, FilePath workspace, Launcher launcher, TaskL
if (testPath.isFile()) {
// Have jar file...
jFile = new JarFile(testPath);
printVersion( listener.getLogger() );
Enumeration<JarEntry> entries = jFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* The MIT License
*
* Copyright 2020 Vector Software, East Greenwich, Rhode Island USA
*
* 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
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.vectorcast.plugins.vectorcastexecution.common;

import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.Optional;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

public class VcastUtils
{
public static Optional< String > getVersion()
{
Optional< String > version = Optional.empty();
try {
File file = new File( URLDecoder.decode( VcastUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath(), "utf-8" ) );
JarFile jarfile = new JarFile( file );
version = Optional.ofNullable( jarfile.getManifest().getMainAttributes().getValue( "Plugin-Version" ) );

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

return version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package com.vectorcast.plugins.vectorcastexecution.job;

import com.vectorcast.plugins.vectorcastexecution.common.VcastUtils;

import hudson.model.Descriptor;
import hudson.model.Project;
import net.sf.json.JSONObject;
Expand Down Expand Up @@ -366,6 +368,7 @@ private String generateJenkinsfile() throws IOException {
"VC_waitTime = '" + getWaitTime() + "'\n" +
"VC_waitLoops = '" + getWaitLoops() + "'\n" +
"VC_useOneCheckoutDir = " + singleCheckout + "\n" +
"VC_createdWithVersion = '" + VcastUtils.getVersion().orElse( "Unknown" ) + "'\n" +
"\n" +
"\n" +
"/* DEBUG JSON RESPONSE: \n" + debugJSON + "\n*/"+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ private void addCommandSingleJob() {
"%VECTORCAST_DIR%\\vpython \"%WORKSPACE%\\vc_scripts\\managewait.py\" --wait_time " + getWaitTime() + " --wait_loops " + getWaitLoops() + " --command_line \"--project \\\"@PROJECT@\\\" --create-report=metrics --output=\\\"@PROJECT_BASE@_metrics_report.html\\\"\"\n" +
"%VECTORCAST_DIR%\\vpython \"%WORKSPACE%\\vc_scripts\\managewait.py\" --wait_time " + getWaitTime() + " --wait_loops " + getWaitLoops() + " --command_line \"--project \\\"@PROJECT@\\\" --create-report=environment --output=\\\"@PROJECT_BASE@_environment_report.html\\\"\"\n" +
"%VECTORCAST_DIR%\\vpython \"%WORKSPACE%\\vc_scripts\\managewait.py\" --wait_time " + getWaitTime() + " --wait_loops " + getWaitLoops() + " --command_line \"--project \\\"@PROJECT@\\\" --full-status > \\\"@PROJECT_BASE@_full_report.txt\\\"\"\n" +
"%VECTORCAST_DIR%\\vpython \"%WORKSPACE%\\vc_scripts\\gen-combined-cov.py\" \"@PROJECT_BASE@_aggregate_report.html\" \"@PROJECT@\"\n" +
"%VECTORCAST_DIR%\\vpython \"%WORKSPACE%\\vc_scripts\\getTotals.py\" \"@PROJECT_BASE@_full_report.txt\"\n";
"%VECTORCAST_DIR%\\vpython \"%WORKSPACE%\\vc_scripts\\generate-results.py\" --junit --final --wait_time " + getWaitTime() + " --wait_loops " + getWaitLoops() + " \"@PROJECT@\" " + noGenExecReport + "\n";
}
win += getEnvironmentTeardownWin() + "\n";
win = StringUtils.replace(win, "@PROJECT@", getManageProjectName());
Expand All @@ -122,8 +121,7 @@ private void addCommandSingleJob() {
"$VECTORCAST_DIR/vpython \"$WORKSPACE/vc_scripts/managewait.py\" --wait_time " + getWaitTime() + " --wait_loops " + getWaitLoops() + " --command_line \"--project \\\"@PROJECT@\\\" --create-report=metrics --output=\\\"@PROJECT_BASE@_metrics_report.html\\\"\"\n" +
"$VECTORCAST_DIR/vpython \"$WORKSPACE/vc_scripts/managewait.py\" --wait_time " + getWaitTime() + " --wait_loops " + getWaitLoops() + " --command_line \"--project \\\"@PROJECT@\\\" --create-report=environment --output=\\\"@PROJECT_BASE@_environment_report.html\\\"\"\n" +
"$VECTORCAST_DIR/vpython \"$WORKSPACE/vc_scripts/managewait.py\" --wait_time " + getWaitTime() + " --wait_loops " + getWaitLoops() + " --command_line \"--project \\\"@PROJECT@\\\" --full-status > \\\"@PROJECT_BASE@_full_report.txt\\\"\"\n" +
"$VECTORCAST_DIR/vpython \"$WORKSPACE/vc_scripts/gen-combined-cov.py\" \"@PROJECT_BASE@_aggregate_report.html\" \"@PROJECT@\"\n" +
"$VECTORCAST_DIR/vpython \"$WORKSPACE/vc_scripts/getTotals.py\" \"@PROJECT_BASE@_full_report.txt\"\n";
"$VECTORCAST_DIR/vpython \"$WORKSPACE/vc_scripts/generate-results.py\" --junit --final --wait_time " + getWaitTime() + " --wait_loops " + getWaitLoops() + " \"@PROJECT@\" " + noGenExecReport + "\n";
}
unix += getEnvironmentTeardownUnix() + "\n";
unix = StringUtils.replace(unix, "@PROJECT@", getManageProjectName());
Expand Down
16 changes: 12 additions & 4 deletions src/main/resources/scripts/baseJenkinsfile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def runCommands(cmds, useLocalCmds = true) {
return log
}

// Fixup name so it doesn't include / or %## or any other special characters
def fixUpName(name) {
return name.replace("/","_").replaceAll('\\%..','_').replaceAll('\\W','_')
}
// transform environment data, a line at a time, into an execution node
// inputString is a space separated string = <<compiler>> <<testsuite>> <<environment>>
// return a node definition based on compiler for the specific job
Expand All @@ -122,7 +126,7 @@ def transformIntoStep(inputString) {
def (compiler, test_suite, environment) = inputString.split()

// set the stashed file name for later
String stashName = "${env.JOB_NAME}_${compiler}_${test_suite}_${environment}-build-execute-stage"
String stashName = fixUpName("${env.JOB_NAME}_${compiler}_${test_suite}_${environment}-build-execute-stage")

// return the auto-generated node and job
// node is based on compiler label
Expand Down Expand Up @@ -173,15 +177,17 @@ def transformIntoStep(inputString) {
buildLogText += runCommands("""_VECTORCAST_DIR/vpython "${env.WORKSPACE}"/vc_scripts/generate-results.py ${VC_Manage_Project} --wait_time ${VC_waitTime} --wait_loops ${VC_waitLoops} --level ${compiler}/${test_suite} -e ${environment} --junit --buildlog build.log""")

if (VC_usingSCM && !VC_useOneCheckoutDir) {
buildLogText = runCommands("""_VECTORCAST_DIR/vpython "${env.WORKSPACE}"/vc_scripts/copy_build_dir.py ${VC_Manage_Project} ${compiler}/${test_suite} ${env.JOB_NAME}_${compiler}_${test_suite}_${environment} ${environment}""" )
def fixedJobName = fixUpName("${env.JOB_NAME}")
buildLogText = runCommands("""_VECTORCAST_DIR/vpython "${env.WORKSPACE}"/vc_scripts/copy_build_dir.py ${VC_Manage_Project} ${compiler}/${test_suite} ${fixedJobName}_${compiler}_${test_suite}_${environment} ${environment}""" )
}
}

writeFile file: "${compiler}_${test_suite}_${environment}_build.log", text: buildLogText

// no cleanup - possible CBT
// use individual names
stash includes: "${compiler}_${test_suite}_${environment}_build.log, **/${compiler}_${test_suite}_${environment}_rebuild.html, **/*.css, **/*.png, execution/*.html, management/*${compiler}_${test_suite}_${environment}*, xml_data/*${compiler}_${test_suite}_${environment}*, ${env.JOB_NAME}_${compiler}_${test_suite}_${environment}_build.tar", name: stashName as String
def fixedJobName = fixUpName("${env.JOB_NAME}")
stash includes: "${compiler}_${test_suite}_${environment}_build.log, **/${compiler}_${test_suite}_${environment}_rebuild.html, **/*.css, **/*.png, execution/*.html, management/*${compiler}_${test_suite}_${environment}*, xml_data/*${compiler}_${test_suite}_${environment}*, ${fixedJobName}_${compiler}_${test_suite}_${environment}_build.tar", name: stashName as String

println "Finished Build-Execute Stage for ${compiler}/${test_suite}/${environment}"

Expand Down Expand Up @@ -261,6 +267,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 Expand Up @@ -312,7 +320,7 @@ pipeline {
// unstash each of the files
EnvList.each {
(compiler, test_suite, environment) = it.split()
String stashName = "${env.JOB_NAME}_${compiler}_${test_suite}_${environment}-build-execute-stage"
String stashName = fixUpName("${env.JOB_NAME}_${compiler}_${test_suite}_${environment}-build-execute-stage")

try {
unstash stashName as String
Expand Down

0 comments on commit b7d68e8

Please sign in to comment.