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:
commit
a1d8ea51f5
@ -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,18 +35,22 @@ 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).
|
||||
|
|
||||
|In following sections of the config.yml the configuration is possible:\n\n'''.stripMargin()
|
||||
|
||||
t += '| parameter | general | step | stage |\n'
|
||||
t += '|-----------|---------|------|-------|\n'
|
||||
t += '| parameter | general | step/stage |\n'
|
||||
t += '|-----------|---------|------------|\n'
|
||||
|
||||
parameters.keySet().toSorted().each {
|
||||
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()
|
||||
@ -332,7 +310,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) {
|
||||
@ -457,20 +435,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 }
|
||||
}
|
||||
|
||||
@ -544,8 +517,7 @@ def handleStep(stepName, prepareDefaultValuesStep, gse) {
|
||||
required: true,
|
||||
|
||||
GENERAL_CONFIG: false,
|
||||
STEP_CONFIG: false,
|
||||
STAGE_CONFIG: false
|
||||
STEP_CONFIG: false
|
||||
]
|
||||
|
||||
// END special handling for 'script' parameter
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -4,7 +4,7 @@ import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
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.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') {
|
||||
|
||||
return new ChangeManagement(nullScript, null) {
|
||||
|
Loading…
Reference in New Issue
Block a user