mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-04 04:07:16 +02:00
Merge remote-tracking branch 'github/master' into HEAD
This commit is contained in:
commit
a1d8ea51f5
@ -1,41 +1,15 @@
|
|||||||
import groovy.io.FileType;
|
import groovy.io.FileType
|
||||||
import org.yaml.snakeyaml.Yaml
|
import org.yaml.snakeyaml.Yaml
|
||||||
import org.codehaus.groovy.control.CompilerConfiguration
|
import org.codehaus.groovy.control.CompilerConfiguration
|
||||||
import com.sap.piper.GenerateDocumentation
|
import com.sap.piper.GenerateDocumentation
|
||||||
import com.sap.piper.DefaultValueCache
|
|
||||||
import java.util.regex.Matcher
|
import java.util.regex.Matcher
|
||||||
|
import groovy.text.StreamingTemplateEngine
|
||||||
|
|
||||||
//
|
//
|
||||||
// Collects helper functions for rendering the docu
|
// Collects helper functions for rendering the docu
|
||||||
//
|
//
|
||||||
class TemplateHelper {
|
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) {
|
static createParametersTable(Map parameters) {
|
||||||
|
|
||||||
def t = ''
|
def t = ''
|
||||||
@ -61,18 +35,22 @@ class TemplateHelper {
|
|||||||
t.trim()
|
t.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static createParametersSection(Map parameters) {
|
||||||
|
createParametersTable(parameters) + '\n' + createParameterDescriptionSection(parameters)
|
||||||
|
}
|
||||||
|
|
||||||
static createStepConfigurationSection(Map parameters) {
|
static createStepConfigurationSection(Map parameters) {
|
||||||
|
|
||||||
def t = '''|We recommend to define values of step parameters via [config.yml file](../configuration.md).
|
def t = '''|We recommend to define values of step parameters via [config.yml file](../configuration.md).
|
||||||
|
|
|
|
||||||
|In following sections of the config.yml the configuration is possible:\n\n'''.stripMargin()
|
|In following sections of the config.yml the configuration is possible:\n\n'''.stripMargin()
|
||||||
|
|
||||||
t += '| parameter | general | step | stage |\n'
|
t += '| parameter | general | step/stage |\n'
|
||||||
t += '|-----------|---------|------|-------|\n'
|
t += '|-----------|---------|------------|\n'
|
||||||
|
|
||||||
parameters.keySet().toSorted().each {
|
parameters.keySet().toSorted().each {
|
||||||
def props = parameters.get(it)
|
def props = parameters.get(it)
|
||||||
t += "| `${it}` | ${props.GENERAL_CONFIG ? 'X' : ''} | ${props.STEP_CONFIG ? 'X' : ''} | ${props.STAGE_CONFIG ? 'X' : ''} |\n"
|
t += "| `${it}` | ${props.GENERAL_CONFIG ? 'X' : ''} | ${props.STEP_CONFIG ? 'X' : ''} |\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
t.trim()
|
t.trim()
|
||||||
@ -332,7 +310,7 @@ class Helper {
|
|||||||
|
|
||||||
stepsDir.traverse(type: FileType.FILES, maxDepth: 0) {
|
stepsDir.traverse(type: FileType.FILES, maxDepth: 0) {
|
||||||
if(it.getName().endsWith('.groovy')) {
|
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())
|
def stepScript = gse.createScript("${scriptName}.groovy", new Binding())
|
||||||
for (def method in stepScript.getClass().getMethods()) {
|
for (def method in stepScript.getClass().getMethods()) {
|
||||||
if(method.getName() == 'call' && method.getAnnotation(GenerateDocumentation) != null) {
|
if(method.getName() == 'call' && method.getAnnotation(GenerateDocumentation) != null) {
|
||||||
@ -457,20 +435,15 @@ void renderStep(stepName, stepProperties) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
def text = theStepDocu.text
|
def binding = [
|
||||||
if(stepProperties.description) {
|
docGenStepName : stepName,
|
||||||
text = TemplateHelper.replaceParagraph(text, 2, 'Description', '\n' + stepProperties.description)
|
docGenDescription : 'Description\n\n' + stepProperties.description,
|
||||||
}
|
docGenParameters : 'Parameters\n\n' + TemplateHelper.createParametersSection(stepProperties.parameters),
|
||||||
if(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 }
|
theStepDocu.withWriter { w -> w.write text }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,8 +517,7 @@ def handleStep(stepName, prepareDefaultValuesStep, gse) {
|
|||||||
required: true,
|
required: true,
|
||||||
|
|
||||||
GENERAL_CONFIG: false,
|
GENERAL_CONFIG: false,
|
||||||
STEP_CONFIG: false,
|
STEP_CONFIG: false
|
||||||
STAGE_CONFIG: false
|
|
||||||
]
|
]
|
||||||
|
|
||||||
// END special handling for 'script' parameter
|
// END special handling for 'script' parameter
|
||||||
|
@ -1,20 +1,14 @@
|
|||||||
# checkChangeInDevelopment
|
# ${docGenStepName}
|
||||||
|
|
||||||
## Description
|
## ${docGenDescription}
|
||||||
|
|
||||||
Content here is generated from corresponding step, see `vars`.
|
|
||||||
|
|
||||||
## Prerequisites
|
## 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.
|
* **[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`.
|
## ${docGenConfiguration}
|
||||||
|
|
||||||
## Step configuration
|
|
||||||
|
|
||||||
Content here is generated from corresponding step, see `vars`.
|
|
||||||
|
|
||||||
## Exceptions
|
## Exceptions
|
||||||
|
|
||||||
|
@ -1,20 +1,14 @@
|
|||||||
# dockerExecute
|
# ${docGenStepName}
|
||||||
|
|
||||||
## Description
|
## ${docGenDescription}
|
||||||
|
|
||||||
Content here is generated from corresponding step, see `vars`.
|
## ${docGenParameters}
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
Content here is generated from corresponding step, see `vars`.
|
|
||||||
|
|
||||||
## Kubernetes support
|
## 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.
|
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
|
## ${docGenConfiguration}
|
||||||
|
|
||||||
Content here is generated from corresponding step, see `vars`.
|
|
||||||
|
|
||||||
## Side effects
|
## Side effects
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
# dockerExecuteOnKubernetes
|
# ${docGenStepName}
|
||||||
|
|
||||||
## Description
|
## ${docGenDescription}
|
||||||
|
|
||||||
Content here is generated from corresponding step, see `vars`.
|
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
@ -11,13 +9,9 @@ Content here is generated from corresponding step, see `vars`.
|
|||||||
|
|
||||||
![Jenkins environment variable configuration](../images/k8s_env.png)
|
![Jenkins environment variable configuration](../images/k8s_env.png)
|
||||||
|
|
||||||
## Parameters
|
## ${docGenParameters}
|
||||||
|
|
||||||
Content here is generated from corresponding step, see `vars`.
|
## ${docGenConfiguration}
|
||||||
|
|
||||||
## Step configuration
|
|
||||||
|
|
||||||
Content here is generated from corresponding step, see `vars`.
|
|
||||||
|
|
||||||
## Side effects
|
## Side effects
|
||||||
|
|
||||||
|
@ -1,21 +1,15 @@
|
|||||||
# karmaExecuteTests
|
# ${docGenStepName}
|
||||||
|
|
||||||
## Description
|
## ${docGenDescription}
|
||||||
|
|
||||||
Content here is generated from corresponnding step, see `vars`.
|
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* **running Karma tests** - have a NPM module with running tests executed with Karma
|
* **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
|
* **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`.
|
## ${docGenConfiguration}
|
||||||
|
|
||||||
## Step configuration
|
|
||||||
|
|
||||||
Content here is generated from corresponnding step, see `vars`.
|
|
||||||
|
|
||||||
## Side effects
|
## Side effects
|
||||||
|
|
||||||
|
@ -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
|
## ${docGenConfiguration}
|
||||||
|
|
||||||
Content here is generated from corresponding step, see `vars`.
|
|
||||||
|
|
||||||
## Exceptions
|
## Exceptions
|
||||||
|
|
||||||
|
@ -1,18 +1,12 @@
|
|||||||
# uiVeri5ExecuteTests
|
# ${docGenStepName}
|
||||||
|
|
||||||
## Description
|
## ${docGenDescription}
|
||||||
|
|
||||||
Content here is generated from corresponding step, see `vars`.
|
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
## Parameters
|
## ${docGenParameters}
|
||||||
|
|
||||||
Content here is generated from corresponding step, see `vars`.
|
## ${docGenConfiguration}
|
||||||
|
|
||||||
## Step configuration
|
|
||||||
|
|
||||||
Content here is generated from corresponding step, see `vars`.
|
|
||||||
|
|
||||||
## Exceptions
|
## Exceptions
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import org.junit.Test
|
|||||||
import org.junit.rules.ExpectedException
|
import org.junit.rules.ExpectedException
|
||||||
import org.junit.rules.RuleChain
|
import org.junit.rules.RuleChain
|
||||||
|
|
||||||
import com.sap.piper.GitUtils
|
import com.sap.piper.cm.BackendType
|
||||||
import com.sap.piper.cm.ChangeManagement
|
import com.sap.piper.cm.ChangeManagement
|
||||||
import com.sap.piper.cm.ChangeManagementException
|
import com.sap.piper.cm.ChangeManagementException
|
||||||
|
|
||||||
@ -155,6 +155,23 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stageConfigIsNotConsideredWithParamKeysTest() {
|
||||||
|
|
||||||
|
nullScript.commonPipelineEnvironment.configuration = [stages:[foo:[changeDocumentId:'12345']]]
|
||||||
|
ChangeManagement cm = getChangeManagementUtils(true, '')
|
||||||
|
|
||||||
|
thrown.expect(IllegalArgumentException)
|
||||||
|
thrown.expectMessage('No changeDocumentId provided.')
|
||||||
|
|
||||||
|
stepRule.step.checkChangeInDevelopment(
|
||||||
|
script: nullScript,
|
||||||
|
cmUtils: cm,
|
||||||
|
changeManagement: [type: BackendType.SOLMAN,
|
||||||
|
endpoint: 'https://example.org/cm'],
|
||||||
|
stageName: 'foo')
|
||||||
|
}
|
||||||
|
|
||||||
private ChangeManagement getChangeManagementUtils(boolean inDevelopment, String changeDocumentId = '001') {
|
private ChangeManagement getChangeManagementUtils(boolean inDevelopment, String changeDocumentId = '001') {
|
||||||
|
|
||||||
return new ChangeManagement(nullScript, null) {
|
return new ChangeManagement(nullScript, null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user