diff --git a/README.md b/README.md index 862162f..f50971b 100644 --- a/README.md +++ b/README.md @@ -8,31 +8,6 @@ Documentation: ## global variables -### addDeployLinks - -Adds a link(to another job) for a specific build from the build history of a jenkins job. -See it's [documentation](vars/addDeployLinks.txt). -This function is a component of the [Integration Pipeline](doc/Integration-Pipeline.md). - -Source: [vars/addDeployLinks.groovy](vars/addDeployLinks.groovy) - -### cleanBuilds - -Cleans up the build history of the jenkins job. It can differentiate deployments to specific environments. -See it's [documentation](vars/cleanBuilds.txt). -This function is a component of the [Integration Pipeline](doc/Integration-Pipeline.md). - -Source: [vars/cleanBuilds.groovy](vars/cleanBuilds.groovy) - -### deployChangedComponents - -This function can be used as a template for deploying a component on a specific environment. -There is no actual implementation of a deployment but a placeholder with an echo output. -See it's [documentation](vars/deployChangedComponents.txt). -This function is a component of the [Integration Pipeline](doc/Integration-Pipeline.md). - -Source: [vars/deployChangedComponents.groovy](vars/deployChangedComponents.groovy) - ### executable Ensures that the given executable is available on the current Jenkins agent, installing it with a Jenkins tool installer @@ -63,23 +38,6 @@ Requests OpenShift to start build from the specified build config and waits for Runs the OWASP dependency-check tool. -### replaceFromVault - -Substitutes variables in a provided String with secrets retrieved from HashiCorp Vault. - -### trackComponentVersions - -This function tracks information about the current deployment state of a component on a specific environment. -See it's [documentation](vars/trackComponentVersions.txt). -This function is a component of the [Integration Pipeline](doc/Integration-Pipeline.md). - -Source: [vars/trackComponentVersions.groovy](vars/trackComponentVersions.groovy) - -### withGitCrypt - -Unlocks the Git repository in the current directory with `git-crypt` for the duration of the scope of the - step and locks it again afterwards. - ## Groovy source files ### DockerHub diff --git a/test/groovy/vars/CheckPipelineTest.groovy b/test/groovy/vars/CheckPipelineTest.groovy deleted file mode 100644 index 5d2a75b..0000000 --- a/test/groovy/vars/CheckPipelineTest.groovy +++ /dev/null @@ -1,51 +0,0 @@ -package groovy.pipeline - -import com.lesfurets.jenkins.unit.declarative.DeclarativePipelineTest -import org.junit.Before -import org.junit.Test - -import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString -import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library -import static com.lesfurets.jenkins.unit.global.lib.ProjectSource.projectSource -import static org.assertj.core.api.Assertions.assertThat - -class CheckPipelineTest extends DeclarativePipelineTest { - - @Before - @Override - void setUp() throws Exception { - super.setUp() - helper.libLoader.preloadLibraryClasses = false - def library = library().name('jenkins-shared-library') - .defaultVersion('master') - .allowOverride(true) - .implicit(true) - .targetPath('') - .retriever(projectSource()) - .build() - helper.registerSharedLibrary(library) - } - - @Test - void itShouldAbortForMissingMandatoryParameter() { - // when - runScript('test/resources/vars/check/mandatoryParameterMissing.groovy') - - // then - assertThat(helper.callStack.findAll { call -> - call.methodName == "error" - }.any { call -> - callArgsToString(call).contains("missing parameter: hallo") - }).isTrue() - printCallStack() - } - - @Test - void itShouldNotAbortForAvailableMandatoryParameter() { - // when - runScript('test/resources/vars/check/mandatoryParameter.groovy') - - // then - assertJobStatusSuccess() - } -} diff --git a/test/groovy/vars/CheckTest.groovy b/test/groovy/vars/CheckTest.groovy deleted file mode 100644 index 952e52b..0000000 --- a/test/groovy/vars/CheckTest.groovy +++ /dev/null @@ -1,56 +0,0 @@ -package groovy.vars - -import static org.assertj.core.api.Assertions.* -import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString - -import com.lesfurets.jenkins.unit.BasePipelineTest -import org.junit.Before -import org.junit.Test - -/** - * Tests for vars/check.groovy - */ -class CheckTest extends BasePipelineTest { - - private Script check - - @Override - @Before - void setUp() { - super.setUp() - check = loadScript('vars/check.groovy') - } - - @Test - void itShouldAbortForMissingMandatoryParameter() { - // given - // Override error behaviour as it is not correctly implemented by the test framework - helper.registerAllowedMethod('error', [String.class]) - check.binding.setVariable('params', [:]) - - // when - check.mandatoryParameter('hallo') - - // then - assertJobStatusAborted() - assertThat(helper.callStack.findAll { call -> - call.methodName == 'error' - }.any { call -> - callArgsToString(call).contains('missing parameter: hallo') - }).isTrue() - } - - @Test - void itShouldNotAbortForAvailableMandatoryParameter() { - // given - check.binding.setVariable('currentBuild', [result: 'null']) - check.binding.setVariable('params', [hallo: 'test']) - - // when - check.mandatoryParameter('hallo') - - // then - assertThat(check.binding.getVariable('currentBuild').result as String).isEqualTo('null') - assertThat(helper.callStack).filteredOn({ it.methodName == 'error' }).isEmpty() - } -} diff --git a/test/groovy/vars/OpenshiftUtilsSpec.groovy b/test/groovy/vars/OpenshiftUtilsSpec.groovy deleted file mode 100644 index 6dc3032..0000000 --- a/test/groovy/vars/OpenshiftUtilsSpec.groovy +++ /dev/null @@ -1,59 +0,0 @@ -package groovy.vars - -import com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification - -class OpenshiftUtilsSpec extends JenkinsPipelineSpecification { - - def openshiftUtils = loadPipelineScriptForTest('vars/openshiftUtils.groovy') - - def 'Applys the template without namespace'() { - setup: - explicitlyMockPipelineVariable('openshift_token') - when: - openshiftUtils.applyTemplate("https://console.appuio.ch/", "my-appuio-project", "template.yaml", "APPUiO_login_token", false) - then: - 1 * getPipelineMock('echo').call('OpenShift server URL: https://console.appuio.ch/') - 1 * getPipelineMock('echo').call('OpenShift project: my-appuio-project') - 1 * getPipelineMock('echo').call('resource file: template.yaml') - 1 * getPipelineMock('withCredentials').call(_) >> { _arguments -> - def credentialsId = 'APPUiO_login_token' - credentialsId == _arguments[0][0].credentialsId[0] - } - 1 * getPipelineMock('tool').call(_) >> '/home/jenkins' - 1 * getPipelineMock('withEnv').call(_) >> { _arguments -> -// TODO: pwd mock - def env = ["KUBECONFIG=null/test/path/.kube", "PATH+OC_HOME=/home/jenkins/bin", "ocpUrl=https://console.appuio.ch/"] - env == _arguments[0][0] - } - 1 * getPipelineMock('sh').call('oc login https://console.appuio.ch/ --insecure-skip-tls-verify=true --token=Mock Generator for [openshift_token]') - 1 * getPipelineMock('sh').call('oc process -f template.yaml | oc apply -f -') - } - - def 'Applys the template with namespace'() { - setup: - explicitlyMockPipelineVariable('openshift_token') - when: - openshiftUtils.applyTemplate("https://console.appuio.ch/", "my-appuio-project", "template.yaml", "APPUiO_login_token", true) - then: - 1 * getPipelineMock('sh').call('oc process -f template.yaml -p NAMESPACE_NAME=$(oc project -q) | oc apply -f -') - } - - def 'Applys the template with envFile and without namespace'() { - setup: - explicitlyMockPipelineVariable('openshift_token') - when: - openshiftUtils.applyTemplateWithEnvFile("https://console.appuio.ch/", "my-appuio-project", "template.yaml", "APPUiO_login_token", 'envFile.env', false) - then: - 1 * getPipelineMock('echo').call('environment file: envFile.env') - 1 * getPipelineMock('sh').call('oc process -f template.yaml --param-file envFile.env | oc apply -f -') - } - - def 'Applys the template with namespace and envFile'() { - setup: - explicitlyMockPipelineVariable('openshift_token') - when: - openshiftUtils.applyTemplateWithEnvFile("https://console.appuio.ch/", "my-appuio-project", "template.yaml", "APPUiO_login_token", 'envFile.env', true) - then: - 1 * getPipelineMock('sh').call('oc process -f template.yaml -p NAMESPACE_NAME=$(oc project -q) --param-file envFile.env | oc apply -f -') - } -}