1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Merge remote-tracking branch 'github/master' into HEAD

This commit is contained in:
Marcus Holl 2019-03-15 15:01:12 +01:00
commit 52f3287cb3
11 changed files with 72 additions and 105 deletions

View File

@ -1,41 +1,15 @@
import groovy.io.FileType;
import groovy.io.FileType
import org.yaml.snakeyaml.Yaml
import org.codehaus.groovy.control.CompilerConfiguration
import com.sap.piper.GenerateDocumentation
import com.sap.piper.DefaultValueCache
import java.util.regex.Matcher
import groovy.text.StreamingTemplateEngine
//
// Collects helper functions for rendering the docu
//
class TemplateHelper {
static replaceParagraph(def textIn, int level, name, replacement) {
boolean insideParagraph = false
def textOut = ''
textIn.eachLine {
line ->
if(insideParagraph && line ==~ "^#{1,${level}} .*\$") {
insideParagraph = false
}
if(! insideParagraph) {
textOut += "${line}\n"
}
if(line ==~ "^#{${level}} ${name}.*\$") {
insideParagraph = true
textOut += "${replacement}\n\n"
}
}
textOut
}
static createParametersTable(Map parameters) {
def t = ''
@ -61,6 +35,10 @@ class TemplateHelper {
t.trim()
}
static createParametersSection(Map parameters) {
createParametersTable(parameters) + '\n' + createParameterDescriptionSection(parameters)
}
static createStepConfigurationSection(Map parameters) {
def t = '''|We recommend to define values of step parameters via [config.yml file](../configuration.md).
@ -331,7 +309,7 @@ class Helper {
stepsDir.traverse(type: FileType.FILES, maxDepth: 0) {
if(it.getName().endsWith('.groovy')) {
def scriptName = (it =~ /vars\/(.*)\.groovy/)[0][1]
def scriptName = (it =~ /vars\${File.separator}(.*)\.groovy/)[0][1]
def stepScript = gse.createScript("${scriptName}.groovy", new Binding())
for (def method in stepScript.getClass().getMethods()) {
if(method.getName() == 'call' && method.getAnnotation(GenerateDocumentation) != null) {
@ -456,20 +434,15 @@ void renderStep(stepName, stepProperties) {
return
}
def text = theStepDocu.text
if(stepProperties.description) {
text = TemplateHelper.replaceParagraph(text, 2, 'Description', '\n' + stepProperties.description)
}
if(stepProperties.parameters) {
def binding = [
docGenStepName : stepName,
docGenDescription : 'Description\n\n' + stepProperties.description,
docGenParameters : 'Parameters\n\n' + TemplateHelper.createParametersSection(stepProperties.parameters),
docGenConfiguration : 'Step configuration\n\n' + TemplateHelper.createStepConfigurationSection(stepProperties.parameters)
]
def template = new StreamingTemplateEngine().createTemplate(theStepDocu.text)
String text = template.make(binding)
text = TemplateHelper.replaceParagraph(text, 2, 'Parameters', '\n' +
TemplateHelper.createParametersTable(stepProperties.parameters) + '\n' +
TemplateHelper.createParameterDescriptionSection(stepProperties.parameters))
text = TemplateHelper.replaceParagraph(text, 2, 'Step configuration', '\n' +
TemplateHelper.createStepConfigurationSection(stepProperties.parameters))
}
theStepDocu.withWriter { w -> w.write text }
}

View File

@ -1,20 +1,14 @@
# checkChangeInDevelopment
# ${docGenStepName}
## Description
Content here is generated from corresponding step, see `vars`.
## ${docGenDescription}
## Prerequisites
* **[Change Management Client 2.0.0 or compatible version](http://central.maven.org/maven2/com/sap/devops/cmclient/dist.cli/)** - available for download on Maven Central.
## Parameters
## ${docGenParameters}
Content here is generated from corresponding step, see `vars`.
## Step configuration
Content here is generated from corresponding step, see `vars`.
## ${docGenConfiguration}
## Exceptions

View File

@ -1,20 +1,14 @@
# dockerExecute
# ${docGenStepName}
## Description
## ${docGenDescription}
Content here is generated from corresponding step, see `vars`.
## Parameters
Content here is generated from corresponding step, see `vars`.
## ${docGenParameters}
## Kubernetes support
If the Jenkins is setup on a Kubernetes cluster, then you can execute the closure inside a container of a pod by setting an environment variable `ON_K8S` to `true`. However, it will ignore `containerPortMappings`, `dockerOptions` and `dockerVolumeBind` values.
## Step configuration
Content here is generated from corresponding step, see `vars`.
## ${docGenConfiguration}
## Side effects

View File

@ -1,8 +1,6 @@
# dockerExecuteOnKubernetes
# ${docGenStepName}
## Description
Content here is generated from corresponding step, see `vars`.
## ${docGenDescription}
## Prerequisites
@ -11,13 +9,9 @@ Content here is generated from corresponding step, see `vars`.
![Jenkins environment variable configuration](../images/k8s_env.png)
## Parameters
## ${docGenParameters}
Content here is generated from corresponding step, see `vars`.
## Step configuration
Content here is generated from corresponding step, see `vars`.
## ${docGenConfiguration}
## Side effects

View File

@ -1,21 +1,15 @@
# karmaExecuteTests
# ${docGenStepName}
## Description
Content here is generated from corresponnding step, see `vars`.
## ${docGenDescription}
## Prerequisites
* **running Karma tests** - have a NPM module with running tests executed with Karma
* **configured WebDriver** - have the [`karma-webdriver-launcher`](https://github.com/karma-runner/karma-webdriver-launcher) package installed and a custom, WebDriver-based browser configured in Karma
## Parameters
## ${docGenParameters}
Content here is generated from corresponnding step, see `vars`.
## Step configuration
Content here is generated from corresponnding step, see `vars`.
## ${docGenConfiguration}
## Side effects

View File

@ -1,16 +1,12 @@
# npmExecute
## Description
# ${docGenStepName}
Content here is generated from corresponding step, see `vars`.
## Parameters
## ${docGenDescription}
Content here is generated from corresponding step, see `vars`.
## ${docGenParameters}
## Step configuration
Content here is generated from corresponding step, see `vars`.
## ${docGenConfiguration}
## Exceptions

View File

@ -1,18 +1,12 @@
# uiVeri5ExecuteTests
# ${docGenStepName}
## Description
Content here is generated from corresponding step, see `vars`.
## ${docGenDescription}
## Prerequisites
## Parameters
## ${docGenParameters}
Content here is generated from corresponding step, see `vars`.
## Step configuration
Content here is generated from corresponding step, see `vars`.
## ${docGenConfiguration}
## Exceptions

View File

@ -55,6 +55,7 @@ def stashWithMessage(name, msg, include = '**/*.*', exclude = '') {
}
def unstash(name, msg = "Unstash failed:") {
def unstashedContent = []
try {
echo "Unstash content: ${name}"
@ -70,7 +71,9 @@ def unstashAll(stashContent) {
def unstashedContent = []
if (stashContent) {
for (i = 0; i < stashContent.size(); i++) {
unstashedContent += unstash(stashContent[i])
if(stashContent[i]) {
unstashedContent += unstash(stashContent[i])
}
}
}
return unstashedContent

View File

@ -38,6 +38,7 @@ class UtilsTest extends BasePiperTest {
void setup() {
parameters = [:]
}
@Test
@ -70,4 +71,11 @@ class UtilsTest extends BasePiperTest {
// generated with "echo -n 'ContinuousDelivery' | sha1sum | sed 's/ -//'"
assertThat(result, is('0dad6c33b6246702132454f604dee80740f399ad'))
}
@Test
void testUnstashAllSkipNull() {
def stashResult = utils.unstashAll(['a', null, 'b'])
assert stashResult == ['a', 'b']
}
}

View File

@ -16,19 +16,30 @@ void call(Map parameters = [:], body) {
echo "--- Begin library step of: ${stepName} ---"
body()
} catch (Throwable err) {
} catch (Throwable error) {
if (verbose)
message += SimpleTemplateEngine.newInstance()
.createTemplate(libraryResource('com.sap.piper/templates/error.log'))
.make([
stepName: stepName,
stepParameters: stepParameters?.toString(),
error: err
error: error
]).toString()
throw err
writeErrorToInfluxData(parameters, error)
throw error
} finally {
if (verbose)
message += "--- End library step of: ${stepName} ---"
echo message
}
}
private void writeErrorToInfluxData(config, error){
def script = config?.stepParameters?.script
if(script && script.commonPipelineEnvironment?.getInfluxCustomDataMapTags().build_error_message == null){
script.commonPipelineEnvironment?.setInfluxCustomDataMapTagsEntry('pipeline_data', 'build_error_step', config.stepName)
script.commonPipelineEnvironment?.setInfluxCustomDataMapTagsEntry('pipeline_data', 'build_error_stage', script.env?.STAGE_NAME)
script.commonPipelineEnvironment?.setInfluxCustomDataMapEntry('pipeline_data', 'build_error_message', error.getMessage())
}
}

View File

@ -74,7 +74,12 @@ import static com.sap.piper.Prerequisites.checkScript
/**
* With `testRepository` the tests can be loaded from another reposirory.
*/
'testRepository'
'testRepository',
/**
* The `testServerUrl` is passed as environment variable `TARGET_SERVER_URL` to the test execution.
* The tests should read the host information from this environment variable in order to be infrastructure agnostic.
*/
'testServerUrl'
])
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
@ -123,6 +128,7 @@ void call(Map parameters = [:]) {
config.stashContent = config.testRepository ? [GitUtils.handleTestRepository(this, config)] : utils.unstashAll(config.stashContent)
config.installCommand = SimpleTemplateEngine.newInstance().createTemplate(config.installCommand).make([config: config]).toString()
config.runCommand = SimpleTemplateEngine.newInstance().createTemplate(config.runCommand).make([config: config]).toString()
config.dockerEnvVars.TARGET_SERVER_URL = config.dockerEnvVars.TARGET_SERVER_URL ?: config.testServerUrl
seleniumExecuteTests(
script: script,