├── test ├── resources │ ├── example-resource.txt │ ├── invalid.json │ ├── example-resource.json │ ├── jenkins-pipeline-library │ │ ├── managedScripts │ │ │ └── shell │ │ │ │ └── maven │ │ │ │ └── purge-snapshots.sh │ │ └── config │ │ │ ├── notify │ │ │ ├── teams.yaml │ │ │ ├── mqtt.yaml │ │ │ ├── mattermost.yaml │ │ │ └── mail.yaml │ │ │ └── generic-config-parser-testdata.yaml │ ├── tools │ │ └── ansible │ │ │ ├── not.existingrole.json │ │ │ └── requirements.yml │ ├── yaml │ │ └── valid.yaml │ ├── credentials │ │ ├── parser-test.json │ │ ├── scm │ │ │ └── credentials.json │ │ ├── http │ │ │ └── credentials.json │ │ └── ssh │ │ │ └── credentials.json │ ├── managedfiles │ │ ├── maven │ │ │ ├── parser-test.json │ │ │ ├── global-settings.json │ │ │ └── settings.json │ │ ├── ruby │ │ │ └── bundle-config.json │ │ └── npm │ │ │ └── npm-config-userconfig.json │ └── jenkinsRestApi │ │ └── findJobsByNameRegex-sample001.json ├── vars │ ├── gitTools │ │ ├── jobs │ │ │ ├── getParentBranchTestJob.groovy │ │ │ ├── getFetchOriginTestJob.groovy │ │ │ ├── getPushOriginTestJob.groovy │ │ │ └── setGitBranchTestJob.groovy │ │ ├── mirrorSsh │ │ │ └── jobs │ │ │ │ ├── shouldFailOnInvalidSrcRepoTestJob.groovy │ │ │ │ ├── shouldFailOnInvalidTargetRepoTestJob.groovy │ │ │ │ ├── shouldFailOnIdenticalServersVariant1TestJob.groovy │ │ │ │ ├── shouldFailOnIdenticalServersVariant2TestJob.groovy │ │ │ │ ├── shouldMirrorRepositoryWithCredentialAutoLookupTestJob.groovy │ │ │ │ └── shouldMirrorRepositoryWithProvidedCredentialsTestJob.groovy │ │ └── mirrorHttps │ │ │ └── jobs │ │ │ ├── shouldMirrorRepositoryWithCredentialAutoLookupTestJob.groovy │ │ │ └── shouldMirrorRepositoryWithProvidedCredentialsTestJob.groovy │ ├── ansible │ │ └── jobs │ │ │ ├── ansibleCheckoutRolesWithPathTestJob.groovy │ │ │ ├── ansibleGetGalaxyRoleInfoWithErrorsTestJob.groovy │ │ │ ├── ansibleGetGalaxyRoleInfoTestJob.groovy │ │ │ ├── ansibleCheckoutRolesWithConfigTestJob.groovy │ │ │ ├── ansibleInstallRolesCustomTestJob.groovy │ │ │ ├── ansibleWrapInstallationTestJob.groovy │ │ │ ├── ansibleExecPlaybookMinimalTestJob.groovy │ │ │ ├── ansibleInstallRolesDefaultTestJob.groovy │ │ │ └── ansibleExecPlaybookInjectParamsTestJob.groovy │ ├── conditionalStage │ │ └── jobs │ │ │ ├── shouldRunConditionalStageTestJob.groovy │ │ │ └── shouldNotRunConditionalStageTestJob.groovy │ ├── credentials │ │ ├── lookupHttpCredential │ │ │ └── jobs │ │ │ │ ├── shouldLookupHttpCredentialTestJob.groovy │ │ │ │ └── shouldNotLookupHttpCredentialTestJob.groovy │ │ ├── lookupSshCredential │ │ │ └── jobs │ │ │ │ ├── shouldLookupSshCredentialTestJob.groovy │ │ │ │ └── shouldNotLookupSshCredentialTestJob.groovy │ │ └── lookupScmCredential │ │ │ └── jobs │ │ │ ├── shouldLookupScmCredentialTestJob.groovy │ │ │ └── shouldNotLookupScmCredentialTestJob.groovy │ ├── notify │ │ ├── teams │ │ │ └── jobs │ │ │ │ ├── notifyTeamsDefaultsJob.groovy │ │ │ │ ├── notifyTeamsDisabledJob.groovy │ │ │ │ └── notifyTeamsCustomJob.groovy │ │ ├── mattermost │ │ │ └── jobs │ │ │ │ ├── notifyMattermostDefaultsJob.groovy │ │ │ │ └── notifyMattermostDisabledJob.groovy │ │ ├── mail │ │ │ └── jobs │ │ │ │ └── notifyMailDefaultsJob.groovy │ │ └── mqtt │ │ │ └── jobs │ │ │ ├── notifyMqttDefaultsJob.groovy │ │ │ └── notifyMqttCustomJob.groovy │ ├── im │ │ ├── teams │ │ │ └── jobs │ │ │ │ ├── imTeamsCustomWebhookUrlJob.groovy │ │ │ │ ├── imTeamsDefaultsJob.groovy │ │ │ │ ├── imTeamsCustomWebhookUrlCredentialJob.groovy │ │ │ │ └── imTeamsConfigJob.groovy │ │ └── mattermost │ │ │ └── jobs │ │ │ ├── imMattermostDefaultsJob.groovy │ │ │ ├── imMattermostCustomEndpointJob.groovy │ │ │ └── imMattermostCustomEndpointCredentialJob.groovy │ ├── setScmUrl │ │ ├── jobs │ │ │ ├── setScmUrlFromShellJob.groovy │ │ │ └── setScmUrlWithConfigJob.groovy │ │ └── SetScmUrlIT.groovy │ ├── setBuildName │ │ ├── jobs │ │ │ └── setBuildNameJob.groovy │ │ └── SetBuildNameIT.groovy │ ├── jenkinsRestApi │ │ └── jobs │ │ │ ├── shouldFindAllJobsTestJob.groovy │ │ │ ├── shouldFindOneJobTestJob.groovy │ │ │ └── shouldFindNoJobTestJob.groovy │ ├── execMaven │ │ └── jobs │ │ │ ├── execMavenWithSettingsViaScmUrlFromEnvJob.groovy │ │ │ ├── execMavenGlobalSettingsJob.groovy │ │ │ ├── execMavenLocalSettingsJob.groovy │ │ │ ├── execMavenWithReturnStatus.groovy │ │ │ ├── execMavenWithReturnStdout.groovy │ │ │ ├── execMavenGlobalAndLocalSettingsJob.groovy │ │ │ ├── execMavenDefaultJob.groovy │ │ │ ├── execMavenCustomCommandTestJob.groovy │ │ │ ├── execMavenWithNPMAndRubyTestJob.groovy │ │ │ ├── execMavenCustomVariant2Job.groovy │ │ │ ├── execMavenCustomVariant1Job.groovy │ │ │ └── execMavenWithBuildParametersTestJob.groovy │ ├── maven │ │ └── jobs │ │ │ ├── purgeSnapshotsDefaultsTestJob.groovy │ │ │ ├── purgeSnapshotsCustomTestJob.groovy │ │ │ └── purgeSnapshotsCustomMapTestJob.groovy │ ├── libraryIntegrationTestBase │ │ └── jobs │ │ │ ├── retryTestJob.groovy │ │ │ ├── shouldFindDescendandsWithoutGlobTestJob.groovy │ │ │ ├── shouldFindNoFileTestJob.groovy │ │ │ ├── shouldFindOneFileTestJob.groovy │ │ │ └── shouldFindMultipleFilesTestJob.groovy │ ├── sshAgentWrapper │ │ └── jobs │ │ │ ├── shouldNotWrapWithSSHAgent.groovy │ │ │ ├── shouldWrapWithStringSSHTarget.groovy │ │ │ ├── shouldWrapWithMultipleSSHTargetsTestJob.groovy │ │ │ └── shouldWrapWithCommandBuilderTestJob.groovy │ ├── logging │ │ ├── LoggingIT.groovy │ │ └── jobs │ │ │ └── shouldInitializeWithinITEnvironmentTestJob.groovy │ ├── execMavenRelease │ │ └── jobs │ │ │ ├── shouldFailWhenScmUrlIsNullTestJob.groovy │ │ │ ├── shouldFailWhenScmUrlIsNotGitSSHTestJob.groovy │ │ │ ├── shouldFailWithNoBranchEnvVarTestJob.groovy │ │ │ ├── shouldExecMavenReleaseWithKeyAgentTestJob.groovy │ │ │ └── shouldFailWithNotAllowedBranchNameTestJob.groovy │ ├── getScmUrl │ │ └── jobs │ │ │ ├── getScmUrlFromEnvVarTestJob.groovy │ │ │ ├── getScmUrlJobNameFallbackTestJob.groovy │ │ │ └── getScmUrlFromConfigTestJob.groovy │ ├── managedScripts │ │ └── jobs │ │ │ ├── jenkinsShellScript │ │ │ ├── shouldExecuteJenkinsShellScriptWithoutCommandBuilderTestJob.groovy │ │ │ ├── shouldExecuteJenkinsShellScriptWithDefaultsTestJob.groovy │ │ │ ├── shouldExecuteJenkinsShellScriptWithReturnStdoutTestJob.groovy │ │ │ ├── shouldExecuteJenkinsShellScriptWithReturnStdoutStatusTestJob.groovy │ │ │ └── shouldExecuteJenkinsShellScriptWithReturnStatusTestJob.groovy │ │ │ └── pipelineShellScript │ │ │ ├── shouldExecutePipelineShellScriptWithoutCommandBuilderTestJob.groovy │ │ │ ├── shouldExecutePipelineShellScriptWithDefaultsTestJob.groovy │ │ │ ├── shouldExecutePipelineShellScriptWithReturnStdoutTestJob.groovy │ │ │ ├── shouldExecutePipelineShellScriptWithReturnStdoutStatusTestJob.groovy │ │ │ └── shouldExecutePipelineShellScriptWithReturnStatusTestJob.groovy │ ├── checkoutScm │ │ └── jobs │ │ │ ├── checkoutWithScmVarJob.groovy │ │ │ ├── checkoutScmEmptyCredentialsJob.groovy │ │ │ ├── checkoutScmDefaultsJob.groovy │ │ │ ├── checkoutScmCustomVariant2Job.groovy │ │ │ ├── checkoutScmCustomVariant3Job.groovy │ │ │ └── checkoutScmCustomVariant1Job.groovy │ ├── execNpm │ │ └── jobs │ │ │ ├── execNpmDefaultTestJob.groovy │ │ │ └── execNpmCustomAndAutoLookupTestJob.groovy │ ├── wrappers │ │ └── jobs │ │ │ ├── shouldWrapColorTestJob.groovy │ │ │ ├── shouldWrapColorOnlyOnceWithSameColorModeTestJob.groovy │ │ │ └── shouldWrapColorMultiWithConfigTestJob.groovy │ ├── setupTools │ │ └── jobs │ │ │ ├── shouldFailWhenToolNotFound.groovy │ │ │ ├── shouldUseDefaultEnvVarsTestJob.groovy │ │ │ └── shouldUseCustomEnvVarsTestJob.groovy │ └── transferScp │ │ └── jobs │ │ ├── transferScpWithMinimalConfiguration.groovy │ │ ├── transferScpSingleTestJob.groovy │ │ └── transferScpRecursiveTestJob.groovy ├── jenkins │ └── plugins │ │ └── http_request │ │ └── ResponseContentSupplierMock.groovy └── io │ └── wcm │ ├── testing │ └── jenkins │ │ └── pipeline │ │ ├── plugins │ │ ├── credentials │ │ │ └── UsernamePasswordMock.groovy │ │ ├── EmailExtPluginMock.groovy │ │ ├── AnsiblePluginMock.groovy │ │ ├── MQTTNotificationPluginMock.groovy │ │ ├── TimestamperPluginMock.groovy │ │ ├── SSHAgentPluginMock.groovy │ │ ├── TeamsNotificationPluginMock.groovy │ │ ├── PipelineStageStepPluginMock.groovy │ │ ├── JUnitPluginMock.groovy │ │ ├── MattermostNotificationPluginMock.groovy │ │ └── AnsiColorPluginMock.groovy │ │ ├── CoreStepsMock.groovy │ │ ├── CpsScriptTestBase.groovy │ │ └── DSLTestBase.groovy │ └── devops │ └── jenkins │ └── pipeline │ ├── credentials │ └── CredentialTest.groovy │ └── utils │ └── logging │ └── LogLevelTest.groovy ├── docs ├── assets │ ├── checkout-scm │ │ ├── mode-2.png │ │ └── checkout-to-local-branch.png │ ├── tutorial-setup │ │ ├── shared-library-001.png │ │ ├── shared-library-002.png │ │ └── shared-library-003.png │ └── exec-managed-shell-script │ │ └── demo-script.png └── usage-examples.md ├── .gitignore ├── vars ├── getScmUrl.md ├── integrationTestUtils.md ├── setBuildName.md ├── setScmUrl.md ├── credentials.md ├── conditionalStage.md ├── jenkinsRestApi.md └── wrappers.md ├── .github └── workflows │ ├── maven-build.yml │ └── maven-deploy.yml ├── assembly └── complete.xml ├── src └── io │ └── wcm │ └── devops │ └── jenkins │ └── pipeline │ ├── shell │ ├── GitCommandBuilderImpl.groovy │ └── ConfigAwareCommandBuilder.groovy │ ├── credentials │ ├── CredentialConstants.groovy │ └── CredentialAware.groovy │ ├── versioning │ └── Item.groovy │ ├── model │ ├── Tool.groovy │ ├── PatternMatchable.groovy │ └── jenkins │ │ └── api │ │ └── Job.groovy │ ├── config │ └── GenericConfigConstants.groovy │ ├── managedfiles │ └── ManagedFile.groovy │ └── utils │ └── maps │ └── MapMergeMode.groovy └── .gitattributes /test/resources/example-resource.txt: -------------------------------------------------------------------------------- 1 | foobar -------------------------------------------------------------------------------- /test/resources/invalid.json: -------------------------------------------------------------------------------- 1 | { 2 | "notvalid": true -------------------------------------------------------------------------------- /test/resources/example-resource.json: -------------------------------------------------------------------------------- 1 | { 2 | "foo": "bar" 3 | } -------------------------------------------------------------------------------- /test/resources/jenkins-pipeline-library/managedScripts/shell/maven/purge-snapshots.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "hello world" 3 | -------------------------------------------------------------------------------- /docs/assets/checkout-scm/mode-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wcm-io-devops/jenkins-pipeline-library/HEAD/docs/assets/checkout-scm/mode-2.png -------------------------------------------------------------------------------- /docs/assets/tutorial-setup/shared-library-001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wcm-io-devops/jenkins-pipeline-library/HEAD/docs/assets/tutorial-setup/shared-library-001.png -------------------------------------------------------------------------------- /docs/assets/tutorial-setup/shared-library-002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wcm-io-devops/jenkins-pipeline-library/HEAD/docs/assets/tutorial-setup/shared-library-002.png -------------------------------------------------------------------------------- /docs/assets/tutorial-setup/shared-library-003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wcm-io-devops/jenkins-pipeline-library/HEAD/docs/assets/tutorial-setup/shared-library-003.png -------------------------------------------------------------------------------- /docs/assets/checkout-scm/checkout-to-local-branch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wcm-io-devops/jenkins-pipeline-library/HEAD/docs/assets/checkout-scm/checkout-to-local-branch.png -------------------------------------------------------------------------------- /docs/assets/exec-managed-shell-script/demo-script.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wcm-io-devops/jenkins-pipeline-library/HEAD/docs/assets/exec-managed-shell-script/demo-script.png -------------------------------------------------------------------------------- /test/resources/tools/ansible/not.existingrole.json: -------------------------------------------------------------------------------- 1 | { 2 | "count": 0, 3 | "next": null, 4 | "next_link": null, 5 | "previous": null, 6 | "previous_link": null, 7 | "results": [] 8 | } 9 | -------------------------------------------------------------------------------- /test/resources/yaml/valid.yaml: -------------------------------------------------------------------------------- 1 | foo: bar 2 | list1: 3 | - entry1 4 | - entry2 5 | - entry3 6 | list2: 7 | - entry1: 8 | key: value1 9 | - entry2: 10 | key: value2 11 | - entry3: 12 | key: value3 13 | -------------------------------------------------------------------------------- /test/resources/credentials/parser-test.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "pattern": "should-be-parsed-credential-pattern", 4 | "id": "should-be-parsed-credential-id", 5 | "comment": "should-be-parsed-credential-comment", 6 | "username": "should-be-parsed-credential-username" 7 | }, 8 | { 9 | "comment": "should-not-be-parsed-comment" 10 | } 11 | ] -------------------------------------------------------------------------------- /test/resources/managedfiles/maven/parser-test.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "pattern": "should-be-parsed-pattern", 4 | "id": "should-be-parsed-id", 5 | "name": "should-be-parsed-name", 6 | "comment": "should-be-parsed-comment" 7 | }, 8 | { 9 | "name": "should-not-be-parsed-name", 10 | "comment": "should-not-be-parsed-comment" 11 | } 12 | ] 13 | -------------------------------------------------------------------------------- /test/resources/credentials/scm/credentials.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "pattern": "git@git-ssh\.domain\.tld", 4 | "id": "ssh-git-credentials-id", 5 | "comment": "ssh-git-credentials-comment" 6 | }, 7 | { 8 | "pattern": "https:\/\/git-http\.domain\.tld", 9 | "id": "https-git-credentials-id", 10 | "comment": "https-git-credentials-comment" 11 | } 12 | ] -------------------------------------------------------------------------------- /test/resources/jenkins-pipeline-library/config/notify/teams.yaml: -------------------------------------------------------------------------------- 1 | - patterns: 2 | - .* 3 | id: "default ms teams notification configuration" 4 | config: 5 | webhookUrlCredentialId: default.credential.id 6 | 7 | - patterns: 8 | - team-a\/.* 9 | id: "default ms teams configuration for all jobs below team-a" 10 | config: 11 | webhookUrlCredentialId: default.credential.id 12 | -------------------------------------------------------------------------------- /test/resources/jenkins-pipeline-library/config/notify/mqtt.yaml: -------------------------------------------------------------------------------- 1 | - patterns: 2 | - .* 3 | id: "default mqtt notification configuration" 4 | config: 5 | broker: defaultbroker 6 | 7 | - patterns: 8 | - team-a\/.* 9 | id: "default mattermost notification configuration" 10 | config: 11 | broker: team-a-broker 12 | credentialsId: team-a-broker-credential-id 13 | qos: "2" 14 | retain: true 15 | -------------------------------------------------------------------------------- /test/resources/managedfiles/ruby/bundle-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "pattern": "subdomain\.npm-domain\.tld[:/]group", 4 | "id": "bundle-config-id", 5 | "name": "bundle-config-name", 6 | "comment": "bundle-config-comment" 7 | }, 8 | { 9 | "pattern": "subdomain\.npm-domain\.tld[:/]group/project1", 10 | "id": "bundle-config-project1-id", 11 | "name": "bundle-config-project1-name", 12 | "comment": "bundle-config-project1-comment" 13 | } 14 | ] 15 | -------------------------------------------------------------------------------- /test/resources/jenkins-pipeline-library/config/notify/mattermost.yaml: -------------------------------------------------------------------------------- 1 | - patterns: 2 | - .* 3 | id: "default mattermost notification configuration" 4 | config: 5 | endpointCredentialId: default.credential.id 6 | channel: jenkins-build-notifications 7 | 8 | - patterns: 9 | - team-a\/.* 10 | id: "default mattermost configuration for all jobs below team-a" 11 | config: 12 | endpointCredentialId: default.credential.id 13 | channel: team-a-jenkins-build-notifications -------------------------------------------------------------------------------- /test/resources/managedfiles/npm/npm-config-userconfig.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "pattern": "subdomain\.npm-domain\.tld[:\/]group", 4 | "id": "npm-user-config-id", 5 | "name": "npm-user-config-name", 6 | "comment": "npm-user-config-comment" 7 | }, 8 | { 9 | "pattern": "subdomain\.npm-domain\.tld[:\/]group/project1", 10 | "id": "npm-user-config-project1-id", 11 | "name": "npm-user-config-project1-name", 12 | "comment": "npm-user-config-project1-comment" 13 | } 14 | ] 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | maven-eclipse.xml 8 | infinitest.filters 9 | 10 | node_modules/ 11 | npm-debug.log 12 | 13 | .nodejs 14 | .project 15 | .classpath 16 | .settings 17 | .externalToolBuilders 18 | .pmd 19 | .checkstyle 20 | .idea 21 | .vagrant 22 | *.iml 23 | .DS_Store 24 | .rubygems 25 | .sass-cache 26 | .rubygems-gem-maven-plugin 27 | *.sublime-* 28 | *nbactions*.xml 29 | .temp/ 30 | 31 | out -------------------------------------------------------------------------------- /test/resources/credentials/http/credentials.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "pattern": "https:\/\/server1", 4 | "id": "http-username-password-credential-for-server1", 5 | "comment": "Username password credential for server1" 6 | }, 7 | { 8 | "pattern": "https:\/\/host1.domain.tld", 9 | "id": "host1-http-credential-id", 10 | "comment": "Username password credential for host1" 11 | }, 12 | { 13 | "pattern": "https:\/\/host2.domain.tld", 14 | "id": "host2-http-credential-id", 15 | "comment": "Username password credential for host2" 16 | } 17 | ] 18 | -------------------------------------------------------------------------------- /test/resources/jenkins-pipeline-library/config/generic-config-parser-testdata.yaml: -------------------------------------------------------------------------------- 1 | - patterns: 2 | - multi-pattern1 3 | - multi-pattern2 4 | id: "multi-pattern-id" 5 | config: 6 | prop: value 7 | list: 8 | - item1 9 | - item2 10 | dict: 11 | subdict1: subvalue1 12 | subdict2: subvalue2 13 | 14 | - pattern: single-pattern 15 | id: "single-pattern-id" 16 | config: 17 | prop_2: value_2 18 | list_2: 19 | - item1_2 20 | - item2_2 21 | dict_2: 22 | subdict1_2: subvalue1_2 23 | subdict2_2: subvalue2_2 -------------------------------------------------------------------------------- /vars/getScmUrl.md: -------------------------------------------------------------------------------- 1 | # getScmUrl(Map config = [:], Boolean jobNameFallback = false) 2 | 3 | The `getScmUrl` is a utility step which will return the url of the current SCM. 4 | 5 | The step tries to retrieve the scm url from the config object first and 6 | does then a fallback to the environment variables `SCM_URL` and then `GIT_URL`. 7 | 8 | If even the `SCM_URL` and `GIT_URL` variables are not set the `JOB_NAME` environment 9 | variable is used when `jobNameFallback` is enabled. 10 | 11 | This step is used for example by: 12 | * [`execMaven`](execMaven.md) 13 | * [`execNpm`](execNpm.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /vars/integrationTestUtils.md: -------------------------------------------------------------------------------- 1 | # integrationTestUtils 2 | 3 | Due to the constantly changing sandbox and CPS implementation 4 | integration tests were introduced in version 0.9. 5 | 6 | The target is to offer test stuff to just test if the Classes and utils 7 | work after a update of the Jenkins and the pipeline plugins 8 | 9 | To enable the reuse of some of the integration test functionalities 10 | some of the test utils were moved to this file. 11 | 12 | These utils are used by: 13 | * [integration-tests](../jenkinsfiles/integration-tests.groovy) 14 | 15 | ## Related classes 16 | * [`IntegrationTestHelper`](../src/io/wcm/devops/jenkins/pipeline/utils/IntegrationTestHelper.groovy) 17 | 18 | 19 | -------------------------------------------------------------------------------- /test/resources/managedfiles/maven/global-settings.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "pattern": "subdomain\.domain\.tld[:\/]group", 4 | "id": "ssh-or-https-id", 5 | "name": "ssh-or-https-name", 6 | "comment": "ssh-or-https-comment" 7 | }, 8 | { 9 | "pattern": "subdomain\.domain\.tld[:\/]group/project1", 10 | "id": "ssh-or-https-better-match-id", 11 | "name": "project1-better-match-name", 12 | "comment": "project1-better-match-comment" 13 | }, 14 | { 15 | "pattern": "subdomain\.evenbetterdomain\.tld", 16 | "id": "EVEN_BETTER_DOMAIN_MVN_GLOBAL_SETTINGS_ID", 17 | "name": "better-domain-global-settings-name", 18 | "comment": "better-domain-global-settings-comment" 19 | } 20 | ] 21 | -------------------------------------------------------------------------------- /.github/workflows/maven-build.yml: -------------------------------------------------------------------------------- 1 | # Default build validation "clean verify" for non-experimental branches 2 | 3 | name: Build 4 | 5 | on: 6 | push: 7 | branches-ignore: 8 | - 'experimental/**' 9 | pull_request: 10 | branches-ignore: 11 | - 'experimental/**' 12 | 13 | jobs: 14 | build: 15 | 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - name: Checkout code 20 | uses: actions/checkout@v4 21 | 22 | - name: Setup JDK 23 | uses: actions/setup-java@v4 24 | with: 25 | distribution: temurin 26 | java-version: 8 27 | cache: maven 28 | 29 | - name: Build and verify 30 | run: mvn -s ./.maven-settings.xml -B -U clean verify 31 | -------------------------------------------------------------------------------- /test/resources/tools/ansible/requirements.yml: -------------------------------------------------------------------------------- 1 | - src: wcm_io_devops.jenkins_pipeline_library 2 | - name: wcm_io_devops.jenkins_facts 3 | - src: wcm_io_devops.jenkins_plugins 4 | version: 1.2.0 5 | - src: https://github.com/wcm-io-devops/ansible-aem-cms.git 6 | name: aem-cms 7 | scm: git 8 | - src: https://github.com/wcm-io-devops/ansible-aem-service.git 9 | name: aem-service 10 | scm: git 11 | version: develop 12 | - src: https://github.com/wcm-io-devops/ansible-conga-aem-smoke-test.git 13 | name: wcm_io_devops.conga_aem_smoke_test 14 | scm: git 15 | version: feature/debug-output 16 | - src: https://github.com/wcm-io-devops/ansible-aem-dispatcher-flush.git 17 | name: wcm_io_devops.aem_dispatcher_flush 18 | version: 1.0.0 19 | scm: git -------------------------------------------------------------------------------- /vars/setBuildName.md: -------------------------------------------------------------------------------- 1 | # setBuildName 2 | 3 | This step will create a versionNumberString and set it as display name 4 | for the build. 5 | 6 | At the moment there are no configuration options for this step 7 | 8 | :bulb: If you want to make the branch name appear in your build call the 9 | [`gitTools.getBranch()`](gitTools.groovy) step before calling this step 10 | 11 | :exclamation: This step requires the [Jenkins Version Number Plugin](https://wiki.jenkins.io/display/JENKINS/Version+Number+Plugin). 12 | 13 | ## `GIT_BRANCH` environment variable available 14 | 15 | When the `GIT_BRANCH` environment variable is present this will be used format: 16 | 17 | `#${BUILD_NUMBER}_${GIT_BRANCH}` 18 | 19 | ## `GIT_BRANCH` environment variable not available 20 | 21 | `#${BUILD_NUMBER}` 22 | -------------------------------------------------------------------------------- /assembly/complete.xml: -------------------------------------------------------------------------------- 1 | 4 | complete 5 | false 6 | 7 | zip 8 | 9 | 10 | 11 | ${basedir} 12 | 13 | resources/**/* 14 | src/**/* 15 | vars/**/* 16 | test/**/* 17 | **/*.md 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.github/workflows/maven-deploy.yml: -------------------------------------------------------------------------------- 1 | # Deploy snapshots to Sonatype OSS repository 2 | 3 | name: Deploy 4 | 5 | on: 6 | workflow_run: 7 | workflows: 8 | - Build 9 | branches: 10 | - master 11 | types: 12 | - completed 13 | 14 | jobs: 15 | deploy: 16 | 17 | runs-on: ubuntu-latest 18 | 19 | steps: 20 | - name: Checkout code 21 | uses: actions/checkout@v4 22 | 23 | - name: Setup JDK 24 | uses: actions/setup-java@v4 25 | with: 26 | distribution: temurin 27 | java-version: 8 28 | cache: maven 29 | 30 | - name: Build, verify, deploy 31 | env: 32 | SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} 33 | SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} 34 | run: mvn -s ./.maven-settings.xml -B -U clean deploy -------------------------------------------------------------------------------- /test/vars/gitTools/jobs/getParentBranchTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.gitTools.jobs 21 | 22 | def execute(Map config = [:]) { 23 | gitTools.getParentBranch() 24 | } 25 | 26 | return this 27 | -------------------------------------------------------------------------------- /test/resources/jenkinsRestApi/findJobsByNameRegex-sample001.json: -------------------------------------------------------------------------------- 1 | { 2 | "_class": "hudson.model.Hudson", 3 | "jobs": [ 4 | { 5 | "_class": "hudson.model.FreeStyleProject", 6 | "name": "job001", 7 | "url": "https://jenkins.example.org/job/job001/", 8 | }, 9 | { 10 | "_class": "com.cloudbees.hudson.plugins.folder.Folder", 11 | "name": "folder", 12 | "url": "https://jenkins.example.org/job/folder/", 13 | "jobs": [ 14 | { 15 | "_class": "org.jenkinsci.plugins.workflow.job.WorkflowJob", 16 | "name": "job002", 17 | "url": "https://jenkins.example.org/job/folder/job/job002/", 18 | }, 19 | { 20 | "_class": "hudson.model.FreeStyleProject", 21 | "name": "job003", 22 | "url": "https://jenkins.example.org/job/folder/job/job003/", 23 | } 24 | ] 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /test/vars/ansible/jobs/ansibleCheckoutRolesWithPathTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMaven.jobs 21 | 22 | def execute() { 23 | ansible.checkoutRoles("tools/ansible/requirements.yml") 24 | } 25 | 26 | return this 27 | -------------------------------------------------------------------------------- /test/vars/gitTools/jobs/getFetchOriginTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.gitTools.jobs 21 | 22 | def execute(Map config = [:]) { 23 | String remotes = config["remotes"] ?: null 24 | gitTools.getFetchOrigin(remotes) 25 | } 26 | 27 | return this 28 | -------------------------------------------------------------------------------- /test/vars/gitTools/jobs/getPushOriginTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.gitTools.jobs 21 | 22 | def execute(Map config = [:]) { 23 | String remotes = config["remotes"] ?: null 24 | gitTools.getPushOrigin(remotes) 25 | } 26 | 27 | return this 28 | -------------------------------------------------------------------------------- /test/vars/conditionalStage/jobs/shouldRunConditionalStageTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | 21 | package vars.conditionalStage.jobs 22 | 23 | def execute() { 24 | conditionalStage("disable", true) { 25 | sh("/bin/true") 26 | } 27 | } 28 | 29 | return this 30 | 31 | -------------------------------------------------------------------------------- /test/vars/conditionalStage/jobs/shouldNotRunConditionalStageTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | 21 | package vars.conditionalStage.jobs 22 | 23 | 24 | def execute() { 25 | conditionalStage("disable", false) { 26 | sh("/bin/true") 27 | } 28 | } 29 | 30 | return this 31 | -------------------------------------------------------------------------------- /test/vars/credentials/lookupHttpCredential/jobs/shouldLookupHttpCredentialTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.credentials.lookupHttpCredential.jobs 21 | 22 | def execute() { 23 | return credentials.lookupHttpCredential("https://server1") 24 | } 25 | 26 | return this 27 | -------------------------------------------------------------------------------- /test/vars/credentials/lookupHttpCredential/jobs/shouldNotLookupHttpCredentialTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.credentials.lookupHttpCredential.jobs 21 | 22 | def execute() { 23 | return credentials.lookupHttpCredential("https://server2") 24 | } 25 | 26 | return this 27 | -------------------------------------------------------------------------------- /test/vars/credentials/lookupSshCredential/jobs/shouldLookupSshCredentialTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | 21 | package vars.credentials.lookupSshCredential.jobs 22 | 23 | def execute() { 24 | return credentials.lookupSshCredential("host3.domain.tld") 25 | } 26 | 27 | return this 28 | -------------------------------------------------------------------------------- /test/vars/credentials/lookupScmCredential/jobs/shouldLookupScmCredentialTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | 21 | package vars.credentials.lookupScmCredential.jobs 22 | 23 | def execute() { 24 | return credentials.lookupScmCredential("git@git-ssh.domain.tld") 25 | } 26 | 27 | return this 28 | -------------------------------------------------------------------------------- /test/vars/credentials/lookupScmCredential/jobs/shouldNotLookupScmCredentialTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | 21 | package vars.credentials.lookupScmCredential.jobs 22 | 23 | def execute() { 24 | return credentials.lookupSshCredential("not-found.domain.tld") 25 | } 26 | 27 | return this 28 | -------------------------------------------------------------------------------- /test/vars/credentials/lookupSshCredential/jobs/shouldNotLookupSshCredentialTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | 21 | package vars.credentials.lookupSshCredential.jobs 22 | 23 | def execute() { 24 | return credentials.lookupSshCredential("not-found.domain.tld") 25 | } 26 | 27 | return this 28 | -------------------------------------------------------------------------------- /test/vars/notify/teams/jobs/notifyTeamsDefaultsJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.notify.teams.jobs 21 | 22 | /** 23 | * Runs notify.teams step with default configuration 24 | * 25 | * @return The script 26 | */ 27 | def execute() { 28 | notify.teams() 29 | } 30 | 31 | return this 32 | -------------------------------------------------------------------------------- /test/vars/notify/mattermost/jobs/notifyMattermostDefaultsJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.notify.mattermost.jobs 21 | 22 | /** 23 | * Runs notify.mattermost step with default configuration 24 | * 25 | * @return The script 26 | */ 27 | def execute() { 28 | notify.mattermost() 29 | } 30 | 31 | return this 32 | -------------------------------------------------------------------------------- /test/vars/notify/mail/jobs/notifyMailDefaultsJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.notify.mail.jobs 21 | 22 | /** 23 | * Runs notifyMail step with default configuration 24 | * 25 | * @return The script 26 | * @see vars.notify.mail.NotifyMailDefaultsIT 27 | */ 28 | def execute() { 29 | notify.mail() 30 | } 31 | 32 | return this 33 | -------------------------------------------------------------------------------- /test/vars/im/teams/jobs/imTeamsCustomWebhookUrlJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.im.teams.jobs 21 | /** 22 | * Runs im.teams step with default configuration 23 | * 24 | * @return The script 25 | */ 26 | def execute() { 27 | im.teams("customMessage", "https://customWebhookUrl", "customColor") 28 | } 29 | 30 | 31 | return this 32 | -------------------------------------------------------------------------------- /test/vars/gitTools/jobs/setGitBranchTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.gitTools.jobs 21 | 22 | /** 23 | * Runs the gitTools.getBranch() task. Environment is manipulated by the integration test to test several variants 24 | * 25 | * @return The script 26 | */ 27 | def execute() { 28 | gitTools.getBranch() 29 | } 30 | 31 | return this 32 | -------------------------------------------------------------------------------- /test/vars/im/teams/jobs/imTeamsDefaultsJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.im.teams.jobs 21 | /** 22 | * Runs im.teams step with default configuration 23 | * 24 | * @return The script 25 | */ 26 | def execute() { 27 | im.teams("customMessageDefaults", "customWebhookUrlDefaults", "customColorDefaults") 28 | } 29 | 30 | 31 | return this 32 | -------------------------------------------------------------------------------- /test/vars/ansible/jobs/ansibleGetGalaxyRoleInfoWithErrorsTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.ansible.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.tools.ansible.Role 23 | 24 | def execute() { 25 | 26 | Role notExistingRole = new Role("not.existingrole") 27 | return ansible.getGalaxyRoleInfo(notExistingRole) 28 | } 29 | 30 | return this 31 | -------------------------------------------------------------------------------- /test/vars/ansible/jobs/ansibleGetGalaxyRoleInfoTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.ansible.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.tools.ansible.Role 23 | 24 | def execute() { 25 | 26 | Role existingRole = new Role("wcm_io_devops.jenkins_pipeline_library") 27 | return ansible.getGalaxyRoleInfo(existingRole) 28 | } 29 | 30 | return this 31 | -------------------------------------------------------------------------------- /test/vars/im/teams/jobs/imTeamsCustomWebhookUrlCredentialJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.im.teams.jobs 21 | /** 22 | * Runs im.teams step with default configuration 23 | * 24 | * @return The script 25 | */ 26 | def execute() { 27 | im.teams("customMessage", "custom-webhookUrl-credential-id", "customColor") 28 | } 29 | 30 | 31 | return this 32 | -------------------------------------------------------------------------------- /test/jenkins/plugins/http_request/ResponseContentSupplierMock.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2019 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package jenkins.plugins.http_request 21 | 22 | import com.sun.mail.iap.Response 23 | 24 | class ResponseContentSupplierMock extends ResponseContentSupplier { 25 | 26 | ResponseContentSupplierMock(String content, int status) { 27 | super(content, status) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/vars/setScmUrl/jobs/setScmUrlFromShellJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.setScmUrl.jobs 21 | 22 | /** 23 | * Runs the setScmUrl step in auto detection mode where scm url is determined via command line 24 | * 25 | * @return The script 26 | * @see vars.setScmUrl.SetScmUrlIT 27 | */ 28 | def execute() { 29 | setScmUrl([:]) 30 | } 31 | 32 | return this 33 | -------------------------------------------------------------------------------- /test/vars/im/mattermost/jobs/imMattermostDefaultsJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.im.mattermost.jobs 21 | /** 22 | * Runs notify.mattermost step with default configuration 23 | * 24 | * @return The script 25 | */ 26 | def execute() { 27 | im.mattermost("customMessageDefaults", "customTextDefaults", "customColorDefaults") 28 | } 29 | 30 | 31 | return this 32 | -------------------------------------------------------------------------------- /test/vars/setBuildName/jobs/setBuildNameJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.setBuildName.jobs 21 | 22 | /** 23 | * Runs the setBuildName step. Environment is manipulated by the integration test to test several variants 24 | * 25 | * @return The script 26 | * @see vars.setBuildName.SetBuildNameIT 27 | */ 28 | def execute() { 29 | setBuildName() 30 | } 31 | 32 | return this 33 | -------------------------------------------------------------------------------- /vars/setScmUrl.md: -------------------------------------------------------------------------------- 1 | # setScmUrl 2 | 3 | With jenkins pipeline the `SCM_URL` environment variable disappeared. 4 | One the one hand this is obvious since you can work with several scms in 5 | one pipeline, on the other hand this functionality is handy when you are 6 | working with one scm. 7 | 8 | Calling this step will bring back this functionality by setting the 9 | `SCM_URL` to the best available value. 10 | 11 | ## Variant 1 (using SCM config) 12 | Assuming you are using the [`checkoutScm`](checkoutScm.groovy) step in 13 | your project the `SCM_URL` will be automatically set by this step. 14 | 15 | In this case the step tries to retrieve the `SCM_URL` from 16 | the config object: 17 | 18 | ```groovy 19 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 20 | 21 | setScmUrl( 22 | (SCM): [ 23 | (SCM_URL): "git@domain.tld/group/project.git" 24 | ] 25 | ) 26 | ``` 27 | 28 | ## Variant 2 (GIT command line) 29 | This variant is the fallback. By calling `git config remote.origin.url` 30 | the remote URL is retrieved and set to the environment variable 31 | -------------------------------------------------------------------------------- /test/vars/jenkinsRestApi/jobs/shouldFindAllJobsTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2019 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.jenkinsRestApi.jobs 21 | 22 | def execute() { 23 | Map remote = [ 24 | regex: ".*", 25 | baseUrl: "https://jenkins.example.org", 26 | credentialsId: "org.example.jenkins.credentials" 27 | ] 28 | 29 | return jenkinsRestApi.findJobsByNameRegex(remote) 30 | } 31 | 32 | return this 33 | -------------------------------------------------------------------------------- /test/vars/jenkinsRestApi/jobs/shouldFindOneJobTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2019 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.jenkinsRestApi.jobs 21 | 22 | def execute() { 23 | Map remote = [ 24 | regex: /job001/, 25 | baseUrl: "https://jenkins.example.org", 26 | credentialsId: "org.example.jenkins.credentials" 27 | ] 28 | 29 | return jenkinsRestApi.findJobsByNameRegex(remote) 30 | } 31 | 32 | return this 33 | -------------------------------------------------------------------------------- /test/vars/execMaven/jobs/execMavenWithSettingsViaScmUrlFromEnvJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMaven.jobs 21 | 22 | /** 23 | * Runs execMaven step without providing the scm url, so execMaven should fallback to SCM_URL environment variable 24 | * 25 | * @return The script 26 | * @see vars.execMaven.ExecMavenIT 27 | */ 28 | def execute() { 29 | execMaven() 30 | } 31 | 32 | return this 33 | -------------------------------------------------------------------------------- /test/io/wcm/testing/jenkins/pipeline/plugins/credentials/UsernamePasswordMock.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.testing.jenkins.pipeline.plugins.credentials 21 | 22 | class UsernamePasswordMock { 23 | String credentialsId 24 | String passwordVariable = null 25 | String usernameVariable = null 26 | 27 | String password = "MOCKED_PASSWORD" 28 | String username = "MOCKED_USERNAME" 29 | } 30 | -------------------------------------------------------------------------------- /test/vars/jenkinsRestApi/jobs/shouldFindNoJobTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2019 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.jenkinsRestApi.jobs 21 | 22 | def execute() { 23 | Map remote = [ 24 | regex: /iDoNotMatchAnyJob/, 25 | baseUrl: "https://jenkins.example.org", 26 | credentialsId: "org.example.jenkins.credentials" 27 | ] 28 | 29 | return jenkinsRestApi.findJobsByNameRegex(remote) 30 | } 31 | 32 | return this 33 | -------------------------------------------------------------------------------- /test/vars/setScmUrl/jobs/setScmUrlWithConfigJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.setScmUrl.jobs 21 | 22 | /** 23 | * Runs the setScmUrl step in default mode where scm url is provided by configuration 24 | * 25 | * @return The script 26 | * @see vars.setScmUrl.SetScmUrlIT 27 | */ 28 | def execute() { 29 | setScmUrl([scm: [url: "http://domain.tld/group/project.git"]]) 30 | } 31 | 32 | return this 33 | -------------------------------------------------------------------------------- /test/vars/maven/jobs/purgeSnapshotsDefaultsTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.maven.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | /** 26 | * Executes the purge snapshots from repository with default settings 27 | */ 28 | def execute() { 29 | maven.purgeSnapshots() 30 | } 31 | 32 | return this 33 | -------------------------------------------------------------------------------- /test/vars/ansible/jobs/ansibleCheckoutRolesWithConfigTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.ansible.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | def execute() { 25 | Map config = [ 26 | (ANSIBLE) : [ 27 | (ANSIBLE_GALAXY_ROLE_FILE): "tools/ansible/requirements.yml" 28 | ] 29 | ] 30 | ansible.checkoutRoles(config) 31 | } 32 | 33 | return this 34 | -------------------------------------------------------------------------------- /test/vars/libraryIntegrationTestBase/jobs/retryTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.libraryIntegrationTestBase.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.environment.EnvironmentConstants 23 | 24 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 25 | 26 | def execute() { 27 | retry(3) { 28 | sh("some_randomly_failing_command") 29 | } 30 | } 31 | 32 | return this 33 | -------------------------------------------------------------------------------- /test/vars/sshAgentWrapper/jobs/shouldNotWrapWithSSHAgent.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.sshAgentWrapper.jobs 21 | /** 22 | * Runs the transferScp step with ssh credential auto lookup (key + username) 23 | * 24 | * @return The script 25 | * @see vars.setScmUrl.SetScmUrlIT 26 | */ 27 | def execute() { 28 | sshAgentWrapper([]) { 29 | sh "echo 'no target at all'" 30 | } 31 | } 32 | 33 | return this 34 | -------------------------------------------------------------------------------- /vars/credentials.md: -------------------------------------------------------------------------------- 1 | # credentials 2 | 3 | This part of the pipeline library provides easy to use functions for credential auto lookup. 4 | 5 | # Table of contents 6 | 7 | * [`lookupHttpCredential`](#lookuphttpcredentialstring-uri) 8 | * [`lookupScmCredential`](#lookupscmcredentialstring-uri) 9 | * [`lookupSshCredential`](#lookupsshcredentialstring-uri) 10 | * [Related classes](#related-classes) 11 | 12 | ## `lookupHttpCredential(String uri)` 13 | 14 | Performs an auto lookup for HTTP (username/password) credentials for the 15 | given `uri`. 16 | 17 | ## `lookupScmCredential(String uri)` 18 | 19 | Performs an auto lookup for SCM credentials for the given `uri`. 20 | 21 | ## `lookupSshCredential(String uri)` 22 | 23 | Performs an auto lookup for SSH credentials for the given `uri`. 24 | 25 | ## Related classes 26 | * [`Credential.groovy`](../src/io/wcm/devops/jenkins/pipeline/credentials/Credential.groovy) 27 | * [CredentialParser.groovy](../src/io/wcm/devops/jenkins/pipeline/credentials/CredentialParser.groovy) 28 | * [PatternMatcher.groovy](../src/io/wcm/devops/jenkins/pipeline/utils/PatternMatcher.groovy) 29 | -------------------------------------------------------------------------------- /test/vars/logging/LoggingIT.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.logging 21 | 22 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestBase 23 | import org.junit.Test 24 | 25 | class LoggingIT extends LibraryIntegrationTestBase { 26 | 27 | @Test 28 | void shouldInitializeWithinITEnvironment() { 29 | loadAndExecuteScript("vars/logging/jobs/shouldInitializeWithinITEnvironmentTestJob.groovy") 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /test/vars/gitTools/mirrorSsh/jobs/shouldFailOnInvalidSrcRepoTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.gitTools.mirrorSsh.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | def execute() { 26 | gitTools.mirrorRepository("invalidRepository","git@github.com:wcm-io-devops/jenkins-pipeline-library.git") 27 | } 28 | 29 | return this 30 | -------------------------------------------------------------------------------- /test/vars/gitTools/mirrorSsh/jobs/shouldFailOnInvalidTargetRepoTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.gitTools.mirrorSsh.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | def execute() { 26 | gitTools.mirrorRepository("git@github.com:wcm-io-devops/jenkins-pipeline-library.git","invalidRepository") 27 | } 28 | 29 | return this 30 | -------------------------------------------------------------------------------- /test/vars/execMavenRelease/jobs/shouldFailWhenScmUrlIsNullTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMavenRelease.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.environment.EnvironmentConstants 23 | 24 | /** 25 | * Runs execMavenRelease step with not supported https url 26 | * 27 | * @return The script 28 | * @see vars.execMavenRelease.ExecMavenReleaseIT 29 | */ 30 | def execute() { 31 | execMavenRelease() 32 | } 33 | 34 | return this 35 | -------------------------------------------------------------------------------- /test/vars/sshAgentWrapper/jobs/shouldWrapWithStringSSHTarget.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.sshAgentWrapper.jobs 21 | /** 22 | * Runs the transferScp step with ssh credential auto lookup (key + username) 23 | * 24 | * @return The script 25 | * @see vars.setScmUrl.SetScmUrlIT 26 | */ 27 | def execute() { 28 | sshAgentWrapper("testserver1.testservers.domain.tld") { 29 | sh "echo 'with string ssh target'" 30 | } 31 | } 32 | 33 | return this 34 | -------------------------------------------------------------------------------- /test/vars/im/mattermost/jobs/imMattermostCustomEndpointJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.im.mattermost.jobs 21 | /** 22 | * Runs notify.mattermost step with default configuration 23 | * 24 | * @return The script 25 | */ 26 | def execute() { 27 | im.mattermost("customEndpointMessage", "customEndpointText", "customEndpointColor", "customEndpointChannel", "customEndpointIcon", "https://customEndpoint", true) 28 | } 29 | 30 | 31 | return this 32 | -------------------------------------------------------------------------------- /src/io/wcm/devops/jenkins/pipeline/shell/GitCommandBuilderImpl.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.devops.jenkins.pipeline.shell 21 | 22 | import org.jenkinsci.plugins.workflow.cps.DSL 23 | 24 | class GitCommandBuilderImpl extends CommandBuilderImpl implements Serializable { 25 | 26 | private static final long serialVersionUID = 1L 27 | 28 | GitCommandBuilderImpl(DSL dsl, String executable = null) { 29 | super(dsl, executable ?: "git") 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/vars/ansible/jobs/ansibleInstallRolesCustomTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.ansible.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | def execute() { 25 | ansible.installRoles( 26 | (ANSIBLE): [ 27 | (ANSIBLE_INSTALLATION) : "ansible-installation", 28 | (ANSIBLE_GALAXY_FORCE): true, 29 | (ANSIBLE_GALAXY_ROLE_FILE): "tools/ansible/requirements.yml" 30 | ] 31 | ) 32 | } 33 | 34 | return this 35 | -------------------------------------------------------------------------------- /test/vars/gitTools/mirrorSsh/jobs/shouldFailOnIdenticalServersVariant1TestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.gitTools.mirrorSsh.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | def execute() { 26 | gitTools.mirrorRepository("git@github.com:wcm-io-devops/jenkins-pipeline-library.git","git@github.com:wcm-io-devops/jenkins-pipeline-library.git") 27 | } 28 | 29 | return this 30 | -------------------------------------------------------------------------------- /test/io/wcm/testing/jenkins/pipeline/CoreStepsMock.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2019 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.testing.jenkins.pipeline 21 | 22 | 23 | import static io.wcm.testing.jenkins.pipeline.StepConstants.FINGERPRINT 24 | 25 | class CoreStepsMock { 26 | 27 | CoreStepsMock(LibraryIntegrationTestContext context) { 28 | context.getPipelineTestHelper().registerAllowedMethod(FINGERPRINT, [String.class], { String pattern -> context.getStepRecorder().record(FINGERPRINT, pattern) }) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/vars/gitTools/mirrorSsh/jobs/shouldFailOnIdenticalServersVariant2TestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.gitTools.mirrorSsh.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | def execute() { 26 | gitTools.mirrorRepository("git@github.com:wcm-io-devops/jenkins-pipeline-library.git","https://github.com/wcm-io-devops/jenkins-pipeline-library.git") 27 | } 28 | 29 | return this 30 | -------------------------------------------------------------------------------- /test/vars/im/mattermost/jobs/imMattermostCustomEndpointCredentialJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.im.mattermost.jobs 21 | /** 22 | * Runs notify.mattermost step with default configuration 23 | * 24 | * @return The script 25 | */ 26 | def execute() { 27 | im.mattermost("customCredentialIdMessage", "customCredentialIdText", "customCredentialIdColor", "customCredentialIdChannel", "customCredentialIdIcon", "custom-endpoint-credential-id", true) 28 | } 29 | 30 | 31 | return this 32 | -------------------------------------------------------------------------------- /test/vars/gitTools/mirrorSsh/jobs/shouldMirrorRepositoryWithCredentialAutoLookupTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.gitTools.mirrorSsh.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | def execute() { 26 | gitTools.mirrorRepository("git@host1.domain.tld:wcm-io-devops/jenkins-pipeline-library.git","git@host2.domain.tld:wcm-io-devops/jenkins-pipeline-library.git") 27 | } 28 | 29 | return this 30 | -------------------------------------------------------------------------------- /test/vars/ansible/jobs/ansibleWrapInstallationTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.ansible.jobs 21 | 22 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestContext 23 | 24 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 25 | 26 | def execute() { 27 | ansible.withInstallation( 28 | (ANSIBLE): [ 29 | (ANSIBLE_INSTALLATION) : LibraryIntegrationTestContext.TOOL_ANSIBLE 30 | ] 31 | ) { 32 | sh("ansible --version") 33 | } 34 | } 35 | 36 | return this 37 | -------------------------------------------------------------------------------- /test/vars/logging/jobs/shouldInitializeWithinITEnvironmentTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.logging.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.utils.logging.LogLevel 23 | import io.wcm.devops.jenkins.pipeline.utils.logging.Logger 24 | 25 | /** 26 | * Runs execNpm step with default configuration by providing only the scm url 27 | * 28 | * @return The script 29 | * @see vars.execMaven.ExecMavenIT 30 | */ 31 | def execute() { 32 | Logger.init(this, LogLevel.INFO) 33 | } 34 | 35 | return this 36 | -------------------------------------------------------------------------------- /test/vars/gitTools/mirrorHttps/jobs/shouldMirrorRepositoryWithCredentialAutoLookupTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.gitTools.mirrorHttps.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | def execute() { 26 | gitTools.mirrorRepository("https://host1.domain.tld/wcm-io-devops/jenkins-pipeline-library.git","https://host2.domain.tld/wcm-io-devops/jenkins-pipeline-library.git") 27 | } 28 | 29 | return this 30 | -------------------------------------------------------------------------------- /test/vars/ansible/jobs/ansibleExecPlaybookMinimalTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMaven.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | def execute() { 25 | 26 | Map config = [ 27 | (ANSIBLE): [ 28 | (ANSIBLE_INSTALLATION): "ansible-1.0.0", 29 | (ANSIBLE_INVENTORY) : "ansible-inventory", 30 | (ANSIBLE_PLAYBOOK) : "ansible-playbook-path" 31 | ] 32 | ] 33 | 34 | ansible.execPlaybook(config) 35 | } 36 | 37 | return this 38 | -------------------------------------------------------------------------------- /test/vars/getScmUrl/jobs/getScmUrlFromEnvVarTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.getScmUrl.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.environment.EnvironmentConstants 23 | 24 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 25 | 26 | /** 27 | * Runs execNpm step with default configuration by providing only the scm url 28 | * 29 | * @return The script 30 | * @see vars.execMaven.ExecMavenIT 31 | */ 32 | def execute() { 33 | return getScmUrl((SCM): [:]) 34 | } 35 | 36 | return this 37 | -------------------------------------------------------------------------------- /test/vars/maven/jobs/purgeSnapshotsCustomTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.maven.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | import io.wcm.devops.jenkins.pipeline.utils.logging.LogLevel 25 | 26 | /** 27 | * Executes the purge snapshots for a custom repo in dry run mode with fatal logLevel 28 | */ 29 | def execute() { 30 | maven.purgeSnapshots('custom/path/to/repo', true, LogLevel.FATAL) 31 | } 32 | 33 | return this 34 | -------------------------------------------------------------------------------- /test/vars/execMavenRelease/jobs/shouldFailWhenScmUrlIsNotGitSSHTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMavenRelease.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Runs execMavenRelease step with not supported https url 26 | * 27 | * @return The script 28 | * @see vars.execMavenRelease.ExecMavenReleaseIT 29 | */ 30 | def execute() { 31 | execMavenRelease( 32 | (SCM): [(SCM_URL): "https://subdomain.domain-new.tld/group/project1.git"], 33 | ) 34 | } 35 | 36 | return this 37 | -------------------------------------------------------------------------------- /test/vars/managedScripts/jobs/jenkinsShellScript/shouldExecuteJenkinsShellScriptWithoutCommandBuilderTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.managedScripts.jobs.jenkinsShellScript 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | /** 26 | * @return The script 27 | * @see vars.managedScripts.MangedPipelineShellScriptIT 28 | */ 29 | def execute() { 30 | return managedScripts.execJenkinsShellScript('jenkins-script-id-5') 31 | } 32 | 33 | return this 34 | -------------------------------------------------------------------------------- /test/vars/getScmUrl/jobs/getScmUrlJobNameFallbackTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.getScmUrl.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.environment.EnvironmentConstants 23 | 24 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 25 | 26 | /** 27 | * Runs execNpm step with default configuration by providing only the scm url 28 | * 29 | * @return The script 30 | * @see vars.execMaven.ExecMavenIT 31 | */ 32 | def execute(Map config) { 33 | return getScmUrl((SCM): [:], config.fallback) 34 | } 35 | 36 | return this 37 | -------------------------------------------------------------------------------- /test/resources/managedfiles/maven/settings.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "pattern": "subdomain\.domain\.tld[:\/]group1", 4 | "id": "group1-maven-settings-id", 5 | "name": "group1-maven-settings-name", 6 | "comment": "group1-maven-settings-comment" 7 | }, 8 | { 9 | "pattern": "subdomain\.domain\.tld[:\/]group1/project1", 10 | "id": "group1-project1-maven-settings-id", 11 | "name": "group1-project1-maven-settings-name", 12 | "comment": "group1-project1-maven-settings-comment" 13 | }, 14 | { 15 | "pattern": "subdomain\.domain\.tld[:\/]group1/project2", 16 | "id": "group1-project2-maven-settings-id", 17 | "name": "group1-project2-maven-settings-name", 18 | "comment": "group1-project2-maven-settings-comment" 19 | }, 20 | { 21 | "pattern": "subdomain\.betterdomain\.tld[:\/]group1/project2", 22 | "id": "BETTER_DOMAIN_MVN_SETTINGS", 23 | "name": "group1-project2-maven-settings-name", 24 | "comment": "group1-project2-maven-settings-comment" 25 | }, 26 | { 27 | "pattern": "subdomain\.evenbetterdomain\.tld[:\/]group1/project2", 28 | "id": "EVEN_BETTER_DOMAIN_MVN_SETTINGS", 29 | "name": "group1-project2-maven-settings-name", 30 | "comment": "group1-project2-maven-settings-comment" 31 | } 32 | ] -------------------------------------------------------------------------------- /test/vars/checkoutScm/jobs/checkoutWithScmVarJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | 21 | package vars.checkoutScm.jobs 22 | 23 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 24 | 25 | /** 26 | * Executes a custom checkout with all supported configuration options that should not use the provided credentialsId 27 | * 28 | * @return The script 29 | * @see vars.checkoutScm.CheckoutScmIT 30 | */ 31 | def execute() { 32 | return checkoutScm([ 33 | (SCM): [ 34 | (SCM_USE_SCM_VAR): true 35 | ] 36 | ]) 37 | } 38 | 39 | return this 40 | -------------------------------------------------------------------------------- /test/vars/libraryIntegrationTestBase/jobs/shouldFindDescendandsWithoutGlobTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.libraryIntegrationTestBase.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.environment.EnvironmentConstants 23 | 24 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 25 | 26 | /** 27 | * Runs execNpm step with default configuration by providing only the scm url 28 | * 29 | * @return The script 30 | * @see vars.execMaven.ExecMavenIT 31 | */ 32 | def execute() { 33 | return findFiles() 34 | } 35 | 36 | return this 37 | -------------------------------------------------------------------------------- /test/vars/execNpm/jobs/execNpmDefaultTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execNpm.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 23 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM_URL 24 | 25 | /** 26 | * Runs execNpm step with default configuration by providing only the scm url 27 | * 28 | * @return The script 29 | * @see vars.execMaven.ExecMavenIT 30 | */ 31 | def execute() { 32 | execNpm((SCM): [(SCM_URL): "https://subdomain.domain-new.tld/group/project1.git"]) 33 | } 34 | 35 | return this 36 | -------------------------------------------------------------------------------- /test/vars/libraryIntegrationTestBase/jobs/shouldFindNoFileTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.libraryIntegrationTestBase.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.environment.EnvironmentConstants 23 | 24 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 25 | 26 | /** 27 | * Runs execNpm step with default configuration by providing only the scm url 28 | * 29 | * @return The script 30 | * @see vars.execMaven.ExecMavenIT 31 | */ 32 | def execute() { 33 | return findFiles(glob: "**/notfound.json") 34 | } 35 | 36 | return this 37 | -------------------------------------------------------------------------------- /test/vars/libraryIntegrationTestBase/jobs/shouldFindOneFileTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.libraryIntegrationTestBase.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.environment.EnvironmentConstants 23 | 24 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 25 | 26 | /** 27 | * Runs execNpm step with default configuration by providing only the scm url 28 | * 29 | * @return The script 30 | * @see vars.execMaven.ExecMavenIT 31 | */ 32 | def execute() { 33 | return findFiles(glob: "**/invalid.json") 34 | } 35 | 36 | return this 37 | -------------------------------------------------------------------------------- /src/io/wcm/devops/jenkins/pipeline/credentials/CredentialConstants.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.devops.jenkins.pipeline.credentials 21 | 22 | /** 23 | * Constants for credentials 24 | */ 25 | class CredentialConstants implements Serializable { 26 | 27 | private static final long serialVersionUID = 1L 28 | 29 | final static SCM_CREDENTIALS_PATH = "credentials/scm/credentials.json" 30 | 31 | final static SSH_CREDENTIALS_PATH = "credentials/ssh/credentials.json" 32 | 33 | final static HTTP_CREDENTIALS_PATH = "credentials/http/credentials.json" 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/io/wcm/devops/jenkins/pipeline/shell/ConfigAwareCommandBuilder.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.devops.jenkins.pipeline.shell 21 | 22 | /** 23 | * Interface for command builders that support the initialization with configuration 24 | */ 25 | interface ConfigAwareCommandBuilder { 26 | 27 | /** 28 | * Initializes the command builder with the provided configuration 29 | * 30 | * @param config The configuration for the commandbuilder 31 | * @return The instance of the command builder 32 | */ 33 | ConfigAwareCommandBuilder applyConfig(Map config) 34 | 35 | } 36 | -------------------------------------------------------------------------------- /test/vars/ansible/jobs/ansibleInstallRolesDefaultTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.ansible.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.utils.logging.LogLevel 23 | import io.wcm.devops.jenkins.pipeline.utils.logging.Logger 24 | 25 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 26 | 27 | def execute() { 28 | ansible.installRoles( 29 | (ANSIBLE): [ 30 | (ANSIBLE_INSTALLATION) : "ansible-installation", 31 | (ANSIBLE_GALAXY_ROLE_FILE) : "tools/ansible/requirements.yml", 32 | ] 33 | ) 34 | } 35 | 36 | return this 37 | -------------------------------------------------------------------------------- /test/vars/notify/mqtt/jobs/notifyMqttDefaultsJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.notify.mqtt.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.utils.maps.MapMergeMode 23 | 24 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 25 | 26 | /** 27 | * Runs notify.mqtt step with default configuration 28 | * 29 | * @return The script 30 | */ 31 | def execute() { 32 | Map config = [:] 33 | /*(NOTIFY_MQTT) : [ 34 | (NOTIFY_MQTT_BROKER) : "tcp://localhost:1883" 35 | ] 36 | ]*/ 37 | notify.mqtt(config) 38 | } 39 | 40 | return this 41 | -------------------------------------------------------------------------------- /test/vars/libraryIntegrationTestBase/jobs/shouldFindMultipleFilesTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.libraryIntegrationTestBase.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.environment.EnvironmentConstants 23 | 24 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 25 | 26 | /** 27 | * Runs execNpm step with default configuration by providing only the scm url 28 | * 29 | * @return The script 30 | * @see vars.execMaven.ExecMavenIT 31 | */ 32 | def execute() { 33 | return findFiles(glob: "**/credentials/**/*.json") 34 | } 35 | 36 | return this 37 | -------------------------------------------------------------------------------- /test/vars/wrappers/jobs/shouldWrapColorTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.wrappers.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.utils.logging.LogLevel 23 | import io.wcm.devops.jenkins.pipeline.utils.logging.Logger 24 | 25 | /** 26 | * Runs the wrap.color step 27 | */ 28 | def execute() { 29 | Logger.init(this, LogLevel.DEBUG) 30 | Logger log = new Logger(this) 31 | 32 | log.info("non colorized output - 1") 33 | 34 | wrappers.color() { 35 | log.info("colorized output") 36 | } 37 | 38 | log.info("non colorized output - 2") 39 | } 40 | 41 | return this 42 | -------------------------------------------------------------------------------- /test/io/wcm/testing/jenkins/pipeline/plugins/EmailExtPluginMock.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.testing.jenkins.pipeline.plugins 21 | 22 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestContext 23 | 24 | import static io.wcm.testing.jenkins.pipeline.StepConstants.EMAILEXT 25 | 26 | class EmailExtPluginMock { 27 | 28 | EmailExtPluginMock(LibraryIntegrationTestContext context) { 29 | context.getPipelineTestHelper().registerAllowedMethod(EMAILEXT, [Map.class], { Map incomingCall -> context.getStepRecorder().record(EMAILEXT, incomingCall) }) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/vars/setupTools/jobs/shouldFailWhenToolNotFound.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.setupTools.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.model.Tool 23 | 24 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 25 | 26 | /** 27 | * Runs the setupTools step with invalid tool to test failure when tool is not found 28 | * 29 | * @return The script 30 | * @see vars.setupTools.SetupToolsIT 31 | */ 32 | def execute() { 33 | setupTools((TOOLS): [ 34 | [(TOOL_NAME): "invalid-maven-tool", (TOOL_TYPE): Tool.MAVEN] 35 | ]) 36 | } 37 | 38 | return this 39 | -------------------------------------------------------------------------------- /test/resources/credentials/ssh/credentials.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "pattern": ".*\.testservers\.domain\.tld", 4 | "id": "ssh-key-for-testservers", 5 | "comment": "SSH key for connecting to test-servers", 6 | "username": "testserveruser" 7 | }, 8 | { 9 | "pattern": "^git@git-ssh\.domain\.tld.+", 10 | "id": "ssh-git-push-credentials-id", 11 | "comment": "ssh-git-push-credentials-comment", 12 | "username": "git-push-username" 13 | }, 14 | { 15 | "pattern": "host1\.domain\.tld", 16 | "id": "host1-ssh-credential-id", 17 | "comment": "domain-ssh-credential-comment", 18 | "username": "domain-ssh-credential-username" 19 | }, 20 | { 21 | "pattern": "host2\.domain\.tld", 22 | "id": "host2-ssh-credential-id", 23 | "comment": "domain-ssh-credential-comment", 24 | "username": "domain-ssh-credential-username" 25 | }, 26 | { 27 | "pattern": "host3\.domain\.tld", 28 | "id": "host3-ssh-credential-id", 29 | "comment": "host3-ssh-credential-comment", 30 | "username": "host3-ssh-credential-username" 31 | }, 32 | { 33 | "pattern": "host3-1\.domain\.tld", 34 | "id": "host3-ssh-credential-id", 35 | "comment": "host3-ssh-credential-comment", 36 | "username": "host3-ssh-credential-username" 37 | } 38 | ] 39 | -------------------------------------------------------------------------------- /test/vars/execMaven/jobs/execMavenGlobalSettingsJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMaven.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 23 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM_URL 24 | 25 | /** 26 | * Runs execMaven step with default configuration to test auto lookup for global maven settings only 27 | * 28 | * @return The script 29 | * @see vars.execMaven.ExecMavenIT 30 | */ 31 | def execute() { 32 | execMaven((SCM): [(SCM_URL): "https://subdomain.domain.tld/group/project1.git"]) 33 | } 34 | 35 | return this 36 | -------------------------------------------------------------------------------- /docs/usage-examples.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | ## Example 1: Building a maven project with notifications 4 | 5 | ```groovy 6 | import io.wcm.devops.jenkins.pipeline.model.Tool 7 | import io.wcm.devops.jenkins.pipeline.utils.logging.LogLevel 8 | import io.wcm.devops.jenkins.pipeline.utils.logging.Logger 9 | 10 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 11 | 12 | Map config = [ 13 | (SCM): [ 14 | (SCM_URL): 'git@git.yourcompany.tld:group/project.git' 15 | ], 16 | (TOOLS): [ 17 | [ (TOOL_NAME): 'apache-maven3', (TOOL_TYPE): Tool.MAVEN ], 18 | [ (TOOL_NAME): 'jdk8', (TOOL_TYPE): Tool.JDK ] 19 | ], 20 | (MAVEN): [ 21 | (MAVEN_GOALS): [ "clean", "install" ] 22 | ], 23 | (LOGLEVEL): LogLevel.INFO 24 | ] 25 | 26 | // surround by try and catch 27 | try { 28 | // initialize the logger 29 | Logger.init(this, config) 30 | node() { 31 | // setup the tools 32 | setupTools(config) 33 | // to the checkout 34 | checkoutScm(config) 35 | // execute maven 36 | execMaven(config) 37 | } 38 | currentBuild.result = "SUCCESS" 39 | } catch (Exception ex) { 40 | currentBuild.result = "FAILED" 41 | throw ex 42 | } finally { 43 | notifyMail(config) 44 | } 45 | ``` 46 | -------------------------------------------------------------------------------- /test/io/wcm/devops/jenkins/pipeline/credentials/CredentialTest.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.devops.jenkins.pipeline.credentials 21 | 22 | import org.junit.Test 23 | 24 | import static org.junit.Assert.assertEquals 25 | 26 | class CredentialTest { 27 | 28 | @Test 29 | void shouldReturnConstructorValues() { 30 | Credential underTest = new Credential("test-pattern", "test-id", "test-comment") 31 | assertEquals("test-pattern", underTest.getPattern()) 32 | assertEquals("test-id", underTest.getId()) 33 | assertEquals("test-comment", underTest.getComment()) 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /test/vars/execMaven/jobs/execMavenLocalSettingsJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMaven.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 23 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM_URL 24 | 25 | /** 26 | * Runs execMaven step with default configuration to test auto lookup for local maven settings only 27 | * 28 | * @return The script 29 | * @see vars.execMaven.ExecMavenIT 30 | */ 31 | def execute() { 32 | execMaven((SCM): [(SCM_URL): "https://subdomain.betterdomain.tld/group1/project2.git"]) 33 | } 34 | 35 | return this 36 | -------------------------------------------------------------------------------- /test/io/wcm/testing/jenkins/pipeline/plugins/AnsiblePluginMock.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.testing.jenkins.pipeline.plugins 21 | 22 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestContext 23 | 24 | import static io.wcm.testing.jenkins.pipeline.StepConstants.ANSIBLE_PLAYBOOK 25 | 26 | class AnsiblePluginMock { 27 | 28 | AnsiblePluginMock(LibraryIntegrationTestContext context) { 29 | context.getPipelineTestHelper().registerAllowedMethod(ANSIBLE_PLAYBOOK, [Map.class], { Map incomingCall -> context.getStepRecorder().record(ANSIBLE_PLAYBOOK, incomingCall) }) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/vars/managedScripts/jobs/pipelineShellScript/shouldExecutePipelineShellScriptWithoutCommandBuilderTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.managedScripts.jobs.pipelineShellScript 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | /** 26 | * @return The script 27 | * @see vars.managedScripts.MangedPipelineShellScriptIT 28 | */ 29 | def execute() { 30 | return managedScripts.execPipelineShellScript('jenkins-pipeline-library/managedScripts/shell/maven/purge-snapshots.sh') 31 | } 32 | 33 | return this 34 | -------------------------------------------------------------------------------- /src/io/wcm/devops/jenkins/pipeline/versioning/Item.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.devops.jenkins.pipeline.versioning 21 | 22 | /** 23 | * Jenkins groovy sandbox compatible version of 24 | * https://github.com/apache/maven/blob/master/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java / Item 25 | */ 26 | interface Item extends Serializable { 27 | 28 | public static int INTEGER_ITEM = 0 29 | public static int STRING_ITEM = 1 30 | public static int LIST_ITEM = 2 31 | 32 | int compareTo(Item item) 33 | 34 | int getType() 35 | 36 | boolean isNull() 37 | 38 | } 39 | -------------------------------------------------------------------------------- /test/vars/checkoutScm/jobs/checkoutScmEmptyCredentialsJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.checkoutScm.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 23 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM_URL 24 | 25 | /** 26 | * Executes default checkout with no credential found during auto lookup for the given scm url 27 | * 28 | * @return The script 29 | * @see vars.checkoutScm.CheckoutScmIT 30 | */ 31 | def execute() { 32 | checkoutScm((SCM): [ 33 | (SCM_URL): "git@unknowndomain.tld/group/project1.git" 34 | ]) 35 | } 36 | 37 | return this 38 | -------------------------------------------------------------------------------- /test/vars/execMaven/jobs/execMavenWithReturnStatus.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMaven.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Runs execMaven step with return status 26 | * 27 | * @return The script 28 | * @see vars.execMaven.ExecMavenIT 29 | */ 30 | def execute() { 31 | return execMaven( 32 | (SCM): [(SCM_URL): "https://subdomain.domain-new.tld/group/project1.git"], 33 | (MAVEN): [ 34 | (MAVEN_POM) : "path/to/returnStatus.xml", 35 | (MAVEN_RETURN_STATUS): true, 36 | ] 37 | ) 38 | } 39 | 40 | return this 41 | -------------------------------------------------------------------------------- /test/vars/execMaven/jobs/execMavenWithReturnStdout.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMaven.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Runs execMaven step with return stdout 26 | * 27 | * @return The script 28 | * @see vars.execMaven.ExecMavenIT 29 | */ 30 | def execute() { 31 | return execMaven( 32 | (SCM): [(SCM_URL): "https://subdomain.domain-new.tld/group/project1.git"], 33 | (MAVEN): [ 34 | (MAVEN_POM) : "path/to/returnStdout.xml", 35 | (MAVEN_RETURN_STDOUT): true, 36 | ] 37 | ) 38 | } 39 | 40 | return this 41 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Declare text files with unix file ending 2 | *.conf text eol=lf 3 | *.config text eol=lf 4 | *.css text eol=lf 5 | *.dtd text eol=lf 6 | *.esp text eol=lf 7 | *.ecma text eol=lf 8 | *.groovy text eol=lf 9 | *.hbrs text eol=lf 10 | *.hbs text eol=lf 11 | *.htm text eol=lf 12 | *.html text eol=lf 13 | *.java text eol=lf 14 | *.jpage text eol=lf 15 | *.js text eol=lf 16 | *.json text eol=lf 17 | *.jsp text eol=lf 18 | *.mustache text eol=lf 19 | *.tld text eol=lf 20 | *.launch text eol=lf 21 | *.log text eol=lf 22 | *.php text eol=lf 23 | *.pl text eol=lf 24 | *.project text eol=lf 25 | *.properties text eol=lf 26 | *.props text eol=lf 27 | *.sass text eol=lf 28 | *.scss text eol=lf 29 | *.sh text eol=lf 30 | *.shtm text eol=lf 31 | *.shtml text eol=lf 32 | *.sql text eol=lf 33 | *.svg text eol=lf 34 | *.txt text eol=lf 35 | *.vm text eol=lf 36 | *.xml text eol=lf 37 | *.xsd text eol=lf 38 | *.xsl text eol=lf 39 | *.xslt text eol=lf 40 | *.yml text eol=lf 41 | *.yaml text eol=lf 42 | 43 | 44 | # Declare windows-specific text files with windows file ending 45 | *.asp text eol=crlf 46 | *.asax text eol=crlf 47 | *.asa text eol=crlf 48 | *.aspx text eol=crlf 49 | *.bat text eol=crlf 50 | *.cmd text eol=crlf 51 | *.cs text eol=crlf 52 | *.csproj text eol=crlf 53 | *.reg text eol=crlf 54 | *.sln text eol=crlf 55 | -------------------------------------------------------------------------------- /test/resources/jenkins-pipeline-library/config/notify/mail.yaml: -------------------------------------------------------------------------------- 1 | - patterns: 2 | - .* 3 | id: "default mail notification configuration" 4 | config: 5 | 6 | 7 | - patterns: 8 | - team-a\/.* 9 | id: "default mail configuration for all jobs below team-a" 10 | config: 11 | attachLog: true 12 | attachmentsPattern: patternFromGenericConfig 13 | body: genericConfigBody 14 | compressLog: false 15 | onSuccess: 16 | enabled: true 17 | body: successBody 18 | subject: successSubject 19 | to: success@company.tld 20 | replyTo: reply-to@company.tld 21 | attachLog: true 22 | compressLog: true 23 | attachmentsPattern: successAttachmentsPattern 24 | recipientProviders: 25 | - $class: 'CulpritsRecipientProvider' 26 | # should take default for onFailure 27 | #onFailure: 28 | # enabled: true 29 | onStillFailing: 30 | enabled: false 31 | onFixed: 32 | enabled: false 33 | onUnstable: 34 | enabled: False 35 | onStillUnstable: 36 | enabled: 0 37 | onAbort: 38 | enabled: false 39 | recipientProviders: 40 | - $class: 'CulpritsRecipientProvider' 41 | - $class: 'RequesterRecipientProvider' 42 | subject: subjectFromGenericConfig 43 | to: generic-config-mail@company.tld 44 | -------------------------------------------------------------------------------- /test/vars/checkoutScm/jobs/checkoutScmDefaultsJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.checkoutScm.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 23 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM_URL 24 | 25 | /** 26 | * Executes default checkout with credential auto lookup for the given scm url 27 | * 28 | * @return The script 29 | * @see vars.checkoutScm.CheckoutScmIT 30 | */ 31 | def execute() { 32 | checkoutScm((SCM): 33 | [ 34 | (SCM_URL): "git@git-ssh.domain.tld/group/project1.git" 35 | ] 36 | ) 37 | } 38 | 39 | return this 40 | -------------------------------------------------------------------------------- /test/vars/execMaven/jobs/execMavenGlobalAndLocalSettingsJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMaven.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 23 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM_URL 24 | 25 | /** 26 | * Runs execMaven step with default configuration to test auto lookup for global and local maven settings 27 | * 28 | * @return The script 29 | * @see vars.execMaven.ExecMavenIT 30 | */ 31 | def execute() { 32 | execMaven((SCM): [(SCM_URL): "https://subdomain.evenbetterdomain.tld/group1/project2.git"]) 33 | } 34 | 35 | return this 36 | -------------------------------------------------------------------------------- /src/io/wcm/devops/jenkins/pipeline/model/Tool.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.devops.jenkins.pipeline.model 21 | 22 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings 23 | 24 | @SuppressFBWarnings('ME_ENUM_FIELD_SETTER') 25 | enum Tool { 26 | 27 | MAVEN("MAVEN_HOME"), 28 | JDK("JAVA_HOME"), 29 | ANSIBLE("ANSIBLE_HOME"), 30 | GIT("GIT_HOME"), 31 | GROOVY("GROOVY_HOME"), 32 | MSBUILD("MSBUILD_HOME"), 33 | ANT("ANT_HOME"), 34 | PYTHON("PYTHON_HOME"), 35 | DOCKER("DOCKER_HOME"), 36 | NODEJS("NPM_HOME") 37 | 38 | String envVar 39 | 40 | Tool(String envVar) { 41 | this.envVar = envVar 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/io/wcm/testing/jenkins/pipeline/CpsScriptTestBase.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.testing.jenkins.pipeline 21 | 22 | import io.wcm.devops.jenkins.pipeline.utils.logging.Logger 23 | import org.junit.Before 24 | 25 | /** 26 | * Base for CpsScript related tests 27 | */ 28 | class CpsScriptTestBase { 29 | 30 | /** 31 | * Mock for CpsScript 32 | */ 33 | CpsScriptMock script 34 | 35 | @Before 36 | void setUp() throws Exception { 37 | this.script = new CpsScriptMock() 38 | // reset logger initialization 39 | Logger.initialized = false 40 | // initialize logger 41 | Logger.init(script) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/io/wcm/testing/jenkins/pipeline/plugins/MQTTNotificationPluginMock.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.testing.jenkins.pipeline.plugins 21 | 22 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestContext 23 | 24 | import static io.wcm.testing.jenkins.pipeline.StepConstants.MQTT_NOTIFICATION 25 | 26 | class MQTTNotificationPluginMock { 27 | 28 | MQTTNotificationPluginMock(LibraryIntegrationTestContext context) { 29 | context.getPipelineTestHelper().registerAllowedMethod(MQTT_NOTIFICATION, [Map.class], { Map incomingCall -> context.getStepRecorder().record(MQTT_NOTIFICATION, incomingCall) }) 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /test/io/wcm/testing/jenkins/pipeline/plugins/TimestamperPluginMock.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.testing.jenkins.pipeline.plugins 21 | 22 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestContext 23 | 24 | import static io.wcm.testing.jenkins.pipeline.StepConstants.TIMESTAMPS 25 | 26 | class TimestamperPluginMock { 27 | 28 | TimestamperPluginMock(LibraryIntegrationTestContext context) { 29 | context.getPipelineTestHelper().registerAllowedMethod(TIMESTAMPS, [Closure.class], { Closure closure -> 30 | context.getStepRecorder().record(TIMESTAMPS, true) 31 | closure.call() 32 | }) 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /test/vars/execMaven/jobs/execMavenDefaultJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMaven.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 23 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM_URL 24 | 25 | /** 26 | * Runs execMaven step with default configuration by providing only the scm url, no global or local maven settings expected 27 | * from auto lookup here 28 | * 29 | * @return The script 30 | * @see vars.execMaven.ExecMavenIT 31 | */ 32 | def execute() { 33 | execMaven((SCM): [(SCM_URL): "https://subdomain.domain-new.tld/group/project1.git"]) 34 | } 35 | 36 | return this 37 | -------------------------------------------------------------------------------- /test/io/wcm/testing/jenkins/pipeline/DSLTestBase.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.testing.jenkins.pipeline 21 | 22 | import io.wcm.devops.jenkins.pipeline.utils.logging.LogLevel 23 | import io.wcm.devops.jenkins.pipeline.utils.logging.Logger 24 | import org.junit.Before 25 | 26 | /** 27 | * Utility base class for all test classes that need a mocked DSL object 28 | */ 29 | class DSLTestBase { 30 | 31 | DSLMock dslMock 32 | 33 | @Before 34 | void setUp() throws Exception { 35 | this.dslMock = new DSLMock() 36 | Logger.initialized = false 37 | // init logger 38 | Logger.init(this.dslMock.getMock(), LogLevel.ALL) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /test/io/wcm/testing/jenkins/pipeline/plugins/SSHAgentPluginMock.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.testing.jenkins.pipeline.plugins 21 | 22 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestContext 23 | 24 | import static io.wcm.testing.jenkins.pipeline.StepConstants.SSH_AGENT 25 | 26 | class SSHAgentPluginMock { 27 | 28 | SSHAgentPluginMock(LibraryIntegrationTestContext context) { 29 | context.getPipelineTestHelper().registerAllowedMethod(SSH_AGENT, [List.class, Closure.class], { List list, Closure closure -> 30 | context.getStepRecorder().record(SSH_AGENT, list) 31 | closure.run() 32 | }) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/io/wcm/testing/jenkins/pipeline/plugins/TeamsNotificationPluginMock.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.testing.jenkins.pipeline.plugins 21 | 22 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestContext 23 | 24 | import static io.wcm.testing.jenkins.pipeline.StepConstants.OFFICE365_CONNECTOR_SEND 25 | 26 | class TeamsNotificationPluginMock { 27 | 28 | TeamsNotificationPluginMock(LibraryIntegrationTestContext context) { 29 | context.getPipelineTestHelper().registerAllowedMethod(OFFICE365_CONNECTOR_SEND, [Map.class], { Map incomingCall -> context.getStepRecorder().record(OFFICE365_CONNECTOR_SEND, incomingCall) }) 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /test/io/wcm/testing/jenkins/pipeline/plugins/PipelineStageStepPluginMock.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.testing.jenkins.pipeline.plugins 21 | 22 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestContext 23 | 24 | import static io.wcm.testing.jenkins.pipeline.StepConstants.STAGE 25 | 26 | class PipelineStageStepPluginMock { 27 | 28 | PipelineStageStepPluginMock(LibraryIntegrationTestContext context) { 29 | context.getPipelineTestHelper().registerAllowedMethod(STAGE, [String.class, Closure.class], { String name, Closure body -> 30 | context.getStepRecorder().record(STAGE, name) 31 | body.run() 32 | }) 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /test/vars/execMavenRelease/jobs/shouldFailWithNoBranchEnvVarTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMavenRelease.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.environment.EnvironmentConstants 23 | 24 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 25 | 26 | /** 27 | * Runs execMavenRelease step with not supported https url 28 | * 29 | * @return The script 30 | * @see vars.execMavenRelease.ExecMavenReleaseIT 31 | */ 32 | def execute() { 33 | env.setProperty(EnvironmentConstants.GIT_BRANCH, null) 34 | execMavenRelease( 35 | (SCM): [(SCM_URL): "git@git-ssh.domain.tld:group/project.git"], 36 | ) 37 | } 38 | 39 | return this 40 | -------------------------------------------------------------------------------- /test/vars/ansible/jobs/ansibleExecPlaybookInjectParamsTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.ansible.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | def execute() { 25 | 26 | Map config = [ 27 | (ANSIBLE): [ 28 | (ANSIBLE_INSTALLATION) : "ansible-inject-params-installation", 29 | (ANSIBLE_INVENTORY) : "ansible-inject-params-inventory", 30 | (ANSIBLE_PLAYBOOK) : "ansible-inject-params-playbook", 31 | (ANSIBLE_EXTRA_VARS) : ["param": "value"], 32 | (ANSIBLE_INJECT_PARAMS): true 33 | ] 34 | ] 35 | 36 | ansible.execPlaybook(config) 37 | } 38 | 39 | return this 40 | -------------------------------------------------------------------------------- /test/vars/execMavenRelease/jobs/shouldExecMavenReleaseWithKeyAgentTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMavenRelease.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.environment.EnvironmentConstants 23 | 24 | /** 25 | * Runs execMavenRelease step with not supported https url 26 | * 27 | * @return The script 28 | * @see vars.execMavenRelease.ExecMavenReleaseIT 29 | */ 30 | def execute() { 31 | env.setProperty(EnvironmentConstants.GIT_BRANCH, "master") 32 | env.setProperty(EnvironmentConstants.SCM_URL, "git@git-ssh.domain.tld:group/project.git") 33 | String test = env.getProperty(EnvironmentConstants.SCM_URL) 34 | execMavenRelease() 35 | } 36 | 37 | return this 38 | -------------------------------------------------------------------------------- /test/vars/transferScp/jobs/transferScpWithMinimalConfiguration.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.transferScp.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Runs the setScmUrl step in auto detection mode where scm url is determined via command line 26 | * 27 | * @return The script 28 | * @see vars.setScmUrl.SetScmUrlIT 29 | */ 30 | def execute() { 31 | transferScp( 32 | (SCP): [ 33 | (SCP_HOST) : "minimal.domain.tld", 34 | (SCP_SOURCE) : '"/path/to/minimal source"', 35 | (SCP_DESTINATION): '"/path/to/minimal destination"' 36 | ] 37 | ) 38 | } 39 | 40 | return this 41 | -------------------------------------------------------------------------------- /test/vars/managedScripts/jobs/jenkinsShellScript/shouldExecuteJenkinsShellScriptWithDefaultsTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.managedScripts.jobs.jenkinsShellScript 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | /** 26 | * @return The script 27 | * @see vars.managedScripts.MangedPipelineShellScriptIT 28 | */ 29 | def execute() { 30 | CommandBuilder commandBuilder = new CommandBuilderImpl(this.steps) 31 | commandBuilder.addPathArgument('jenkinsScript/path/1') 32 | return managedScripts.execJenkinsShellScript('jenkins-script-id-1', commandBuilder) 33 | } 34 | 35 | return this 36 | -------------------------------------------------------------------------------- /test/vars/execNpm/jobs/execNpmCustomAndAutoLookupTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execNpm.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Runs execNpm step with default configuration by providing only the scm url 26 | * 27 | * @return The script 28 | * @see vars.execMaven.ExecMavenIT 29 | */ 30 | def execute() { 31 | execNpm( 32 | (SCM): [ 33 | (SCM_URL): "https://subdomain.npm-domain.tld/group/some-project.git" 34 | ], 35 | (NPM): [ 36 | (NPM_EXECUTABLE): "/path/to/custom/npm", 37 | (NPM_ARGUMENTS) : ["run", "build", "-flag", "--property=value"] 38 | ]) 39 | } 40 | 41 | return this 42 | -------------------------------------------------------------------------------- /test/vars/gitTools/mirrorHttps/jobs/shouldMirrorRepositoryWithProvidedCredentialsTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.gitTools.mirrorHttps.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | def execute() { 26 | List srcCredentialIds = [ 27 | "host1-http-credential-id", 28 | ] 29 | List targetCredentialIds = [ 30 | "host2-http-credential-id", 31 | ] 32 | gitTools.mirrorRepository("https://host1.domain.tld/wcm-io-devops/jenkins-pipeline-library.git","https://host2.domain.tld:wcm-io-devops/jenkins-pipeline-library.git", srcCredentialIds, targetCredentialIds) 33 | } 34 | 35 | return this 36 | -------------------------------------------------------------------------------- /test/vars/maven/jobs/purgeSnapshotsCustomMapTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.maven.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.utils.logging.LogLevel 23 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 24 | 25 | /** 26 | * Executes the purge snapshots for a custom repo in dry run mode with fatal logLevel 27 | */ 28 | def execute() { 29 | Map config = [ 30 | (MAVEN_PURGE_SNAPSHOTS) : [ 31 | (MAVEN_PURGE_SNAPSHOTS_REPO_PATH): 'custom/path/to/repo/from/map', 32 | (MAVEN_PURGE_SNAPSHOTS_DRY_RUN): true, 33 | (MAVEN_PURGE_SNAPSHOTS_LOG_LEVEL) : LogLevel.TRACE 34 | ] 35 | ] 36 | maven.purgeSnapshots(config) 37 | } 38 | 39 | return this 40 | -------------------------------------------------------------------------------- /test/vars/getScmUrl/jobs/getScmUrlFromConfigTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.getScmUrl.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.environment.EnvironmentConstants 23 | 24 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 25 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM_URL 26 | 27 | 28 | /** 29 | * Runs execNpm step with default configuration by providing only the scm url 30 | * 31 | * @return The script 32 | * @see vars.execMaven.ExecMavenIT 33 | */ 34 | def execute() { 35 | env.setProperty(EnvironmentConstants.SCM_URL, "scm-url-from-env-var") 36 | return getScmUrl((SCM): [(SCM_URL): "scm-url-from-scm-config"]) 37 | } 38 | 39 | return this 40 | -------------------------------------------------------------------------------- /test/vars/execMaven/jobs/execMavenCustomCommandTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMaven.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Runs execMaven step with path to custom maven executable 26 | * 27 | * @return The script 28 | * @see vars.execMaven.ExecMavenIT 29 | */ 30 | def execute() { 31 | execMaven( 32 | (SCM): [(SCM_URL): "https://subdomain.domain-new.tld/group/project1.git"], 33 | (MAVEN): [ 34 | (MAVEN_EXECUTABLE): "time /path/to/custom/maven", 35 | (MAVEN_POM) : "path/to/customPom1.xml", 36 | (MAVEN_GOALS) : ["customGoal1", "customGoal2"] 37 | ] 38 | ) 39 | } 40 | 41 | return this 42 | -------------------------------------------------------------------------------- /test/vars/execMaven/jobs/execMavenWithNPMAndRubyTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMaven.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 23 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM_URL 24 | 25 | /** 26 | * Runs execMaven step with default configuration and the configFile auto lookup should add local and global maven settings, 27 | * NPM and Ruby specific configuration files via environment variables 28 | * 29 | * @return The script 30 | * @see vars.execMaven.ExecMavenIT 31 | */ 32 | def execute() { 33 | execMaven( 34 | (SCM): [(SCM_URL): "https://subdomain.npm-domain.tld/group/project1.git"], 35 | ) 36 | } 37 | 38 | return this 39 | -------------------------------------------------------------------------------- /src/io/wcm/devops/jenkins/pipeline/credentials/CredentialAware.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.devops.jenkins.pipeline.credentials 21 | 22 | import com.cloudbees.groovy.cps.NonCPS 23 | 24 | /** 25 | * Interface for command builders that support credentials 26 | */ 27 | interface CredentialAware { 28 | 29 | /** 30 | * Used to set the username based on a Credential found by auto lookup 31 | * 32 | * @param credential The credential object to use the username from (if set) 33 | */ 34 | @NonCPS 35 | void setCredential(Credential credential) 36 | 37 | /** 38 | * Getter function for credentials 39 | * 40 | * @return The stored credentials 41 | */ 42 | @NonCPS 43 | Credential getCredential() 44 | } 45 | -------------------------------------------------------------------------------- /test/io/wcm/testing/jenkins/pipeline/plugins/JUnitPluginMock.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.testing.jenkins.pipeline.plugins 21 | 22 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestContext 23 | 24 | import static io.wcm.testing.jenkins.pipeline.StepConstants.JUNIT 25 | 26 | class JUnitPluginMock { 27 | 28 | JUnitPluginMock(LibraryIntegrationTestContext context) { 29 | context.getPipelineTestHelper().registerAllowedMethod(JUNIT, [String.class], { String incomingCall -> context.getStepRecorder().record(JUNIT, incomingCall) }) 30 | context.getPipelineTestHelper().registerAllowedMethod(JUNIT, [Map.class], { Map incomingCall -> context.getStepRecorder().record(JUNIT, incomingCall) }) 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /test/vars/managedScripts/jobs/pipelineShellScript/shouldExecutePipelineShellScriptWithDefaultsTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.managedScripts.jobs.pipelineShellScript 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | /** 26 | * @return The script 27 | * @see vars.managedScripts.MangedPipelineShellScriptIT 28 | */ 29 | def execute() { 30 | CommandBuilder commandBuilder = new CommandBuilderImpl(this.steps) 31 | commandBuilder.addPathArgument('path/to/repo') 32 | return managedScripts.execPipelineShellScript('jenkins-pipeline-library/managedScripts/shell/maven/purge-snapshots.sh', commandBuilder) 33 | } 34 | 35 | return this 36 | -------------------------------------------------------------------------------- /test/vars/checkoutScm/jobs/checkoutScmCustomVariant2Job.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.checkoutScm.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Executes a custom checkout with the provided userRemoteConfigs that should not use the provided credentialsId and the scm url 26 | * 27 | * @return The script 28 | * 29 | * @see vars.checkoutScm.CheckoutScmIT 30 | */ 31 | def execute() { 32 | checkoutScm((SCM): [ 33 | (SCM_CREDENTIALS_ID) : 'NOT_USED_CREDENTIAL', 34 | (SCM_URL) : 'NOT_USED_URL', 35 | (SCM_USER_REMOTE_CONFIGS): [[credentialsId: 'USER_REMOTE_CONFIGS_CREDENTIAL', url: 'USER_REMOTE_CONFIGS_URL']] 36 | ]) 37 | } 38 | 39 | return this 40 | -------------------------------------------------------------------------------- /test/vars/checkoutScm/jobs/checkoutScmCustomVariant3Job.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.checkoutScm.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Executes a custom checkout with the provided userRemoteConfig that should not use the provided credentialsId 26 | * 27 | * @return The script 28 | * @see vars.checkoutScm.CheckoutScmIT 29 | */ 30 | def execute() { 31 | checkoutScm((SCM): [ 32 | (SCM_URL) : "git@git-ssh.betterdomain.tld/group/project1.git", 33 | (SCM_CREDENTIALS_ID) : "SHOULD_NOT_USE_ME", 34 | (SCM_USER_REMOTE_CONFIG): [credentialsId: 'USER_REMOTE_CONFIG_CREDENTIAL', url: 'USER_REMOTE_CONFIG_URL'] 35 | ]) 36 | } 37 | 38 | return this 39 | -------------------------------------------------------------------------------- /src/io/wcm/devops/jenkins/pipeline/config/GenericConfigConstants.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.devops.jenkins.pipeline.config 21 | 22 | /** 23 | * Constants for generic configurations 24 | */ 25 | class GenericConfigConstants implements Serializable{ 26 | private static final long serialVersionUID = 1L 27 | 28 | static final String NOTIFY_MAIL_CONFIG_PATH = "jenkins-pipeline-library/config/notify/mail.yaml" 29 | static final String NOTIFY_MATTERMOST_CONFIG_PATH = "jenkins-pipeline-library/config/notify/mattermost.yaml" 30 | static final String NOTIFY_MQTT_CONFIG_PATH = "jenkins-pipeline-library/config/notify/mqtt.yaml" 31 | static final String NOTIFY_TEAMS_CONFIG_PATH = "jenkins-pipeline-library/config/notify/teams.yaml" 32 | 33 | } 34 | -------------------------------------------------------------------------------- /test/io/wcm/devops/jenkins/pipeline/utils/logging/LogLevelTest.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.devops.jenkins.pipeline.utils.logging 21 | 22 | import org.junit.Test 23 | 24 | import static org.junit.Assert.assertEquals 25 | 26 | class LogLevelTest { 27 | 28 | @Test 29 | void shouldReturnDefaultLogLevel() { 30 | assertEquals(LogLevel.INFO, LogLevel.fromInteger(-1)) 31 | assertEquals(LogLevel.INFO, LogLevel.fromInteger(9546131)) 32 | assertEquals(LogLevel.INFO, LogLevel.fromString("unknown")) 33 | } 34 | 35 | @Test 36 | void shouldReturnCorrectValue() { 37 | assertEquals(0, LogLevel.ALL.getLevel()) 38 | assertEquals(4, LogLevel.INFO.getLevel()) 39 | assertEquals(Integer.MAX_VALUE, LogLevel.NONE.getLevel()) 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /test/vars/execMavenRelease/jobs/shouldFailWithNotAllowedBranchNameTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMavenRelease.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.environment.EnvironmentConstants 23 | 24 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 25 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM_URL 26 | 27 | /** 28 | * Runs execMavenRelease step with not supported https url 29 | * 30 | * @return The script 31 | * @see vars.execMavenRelease.ExecMavenReleaseIT 32 | */ 33 | def execute() { 34 | env.setProperty(EnvironmentConstants.GIT_BRANCH, "develop") 35 | execMavenRelease( 36 | (SCM): [(SCM_URL): "git@git-ssh.domain.tld:group/project.git"], 37 | ) 38 | } 39 | 40 | return this 41 | -------------------------------------------------------------------------------- /test/vars/managedScripts/jobs/jenkinsShellScript/shouldExecuteJenkinsShellScriptWithReturnStdoutTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.managedScripts.jobs.jenkinsShellScript 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | /** 26 | * @return The script 27 | * @see vars.managedScripts.MangedPipelineShellScriptIT 28 | */ 29 | def execute() { 30 | CommandBuilder commandBuilder = new CommandBuilderImpl(this.steps) 31 | commandBuilder.addPathArgument('jenkinsScript/path/4') 32 | commandBuilder.addArguments(['arg3','arg4']) 33 | return managedScripts.execJenkinsShellScript('jenkins-script-id-4', commandBuilder, true, false) 34 | } 35 | 36 | return this 37 | -------------------------------------------------------------------------------- /test/vars/setupTools/jobs/shouldUseDefaultEnvVarsTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.setupTools.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.model.Tool 23 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestContext 24 | 25 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 26 | 27 | /** 28 | * Runs the setupTools step with default environment variables for JDK and Maven 29 | * 30 | * @return The script 31 | * @see vars.setupTools.SetupToolsIT 32 | */ 33 | def execute() { 34 | setupTools((TOOLS): [ 35 | [(TOOL_NAME): LibraryIntegrationTestContext.TOOL_JDK, (TOOL_TYPE): Tool.JDK], 36 | [(TOOL_NAME): LibraryIntegrationTestContext.TOOL_MAVEN, (TOOL_TYPE): Tool.MAVEN] 37 | ]) 38 | } 39 | 40 | return this 41 | -------------------------------------------------------------------------------- /test/vars/sshAgentWrapper/jobs/shouldWrapWithMultipleSSHTargetsTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.sshAgentWrapper.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.ssh.SSHTarget 23 | 24 | /** 25 | * Runs the transferScp step with ssh credential auto lookup (key + username) 26 | * 27 | * @return The script 28 | * @see vars.setScmUrl.SetScmUrlIT 29 | */ 30 | def execute() { 31 | 32 | List sshTargets = [ 33 | new SSHTarget("host1.domain.tld"), 34 | new SSHTarget("host2.domain.tld"), 35 | new SSHTarget("host3.domain.tld"), 36 | new SSHTarget("host3-1.domain.tld") 37 | ] 38 | 39 | sshAgentWrapper(sshTargets) { 40 | sh "echo 'multiple ssh targets'" 41 | } 42 | 43 | return sshTargets 44 | } 45 | 46 | 47 | return this 48 | -------------------------------------------------------------------------------- /test/vars/gitTools/mirrorSsh/jobs/shouldMirrorRepositoryWithProvidedCredentialsTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.gitTools.mirrorSsh.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | def execute() { 26 | List srcCredentialIds = [ 27 | "src-cred-1", 28 | "src-cred-2", 29 | "src-cred-3", 30 | ] 31 | List targetCredentialIds = [ 32 | "target-cred-1", 33 | "target-cred-2", 34 | "target-cred-3", 35 | ] 36 | gitTools.mirrorRepository("git@host1.domain.tld:wcm-io-devops/jenkins-pipeline-library.git","git@host2.domain.tld:wcm-io-devops/jenkins-pipeline-library.git", srcCredentialIds, targetCredentialIds) 37 | } 38 | 39 | return this 40 | -------------------------------------------------------------------------------- /test/vars/managedScripts/jobs/jenkinsShellScript/shouldExecuteJenkinsShellScriptWithReturnStdoutStatusTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.managedScripts.jobs.jenkinsShellScript 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | /** 26 | * @return The script 27 | * @see vars.managedScripts.MangedPipelineShellScriptIT 28 | */ 29 | def execute() { 30 | CommandBuilder commandBuilder = new CommandBuilderImpl(this.steps) 31 | commandBuilder.addPathArgument('jenkinsScript/path/3') 32 | commandBuilder.addArgument('argName', 'argValue') 33 | return managedScripts.execJenkinsShellScript('jenkins-script-id-3', commandBuilder, true, true) 34 | } 35 | 36 | return this 37 | -------------------------------------------------------------------------------- /test/vars/notify/mqtt/jobs/notifyMqttCustomJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.notify.mqtt.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Runs notify.mqtt step with default configuration 26 | * 27 | * @return The script 28 | */ 29 | def execute() { 30 | Map config = [ 31 | (NOTIFY_MQTT) : [ 32 | (NOTIFY_MQTT_BROKER) : "tcp://custom-broker:1883", 33 | (NOTIFY_MQTT_CREDENTIALS_ID): 'custom-credential-id', 34 | (NOTIFY_MQTT_TOPIC) : "custom-topic", 35 | (NOTIFY_MQTT_MESSAGE) : "custom-message", 36 | (NOTIFY_MQTT_QOS) : "1", 37 | (NOTIFY_MQTT_RETAIN) : true, 38 | ] 39 | ] 40 | notify.mqtt(config) 41 | } 42 | 43 | return this 44 | -------------------------------------------------------------------------------- /test/vars/managedScripts/jobs/jenkinsShellScript/shouldExecuteJenkinsShellScriptWithReturnStatusTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.managedScripts.jobs.jenkinsShellScript 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | /** 26 | * @return The script 27 | * @see vars.managedScripts.MangedPipelineShellScriptIT 28 | */ 29 | def execute() { 30 | CommandBuilder commandBuilder = new CommandBuilderImpl(this.steps) 31 | commandBuilder.addPathArgument('jenkinsScript/path/2') 32 | commandBuilder.addArgument('arg1') 33 | commandBuilder.addArgument('arg2') 34 | return managedScripts.execJenkinsShellScript('jenkins-script-id-2', commandBuilder, false, true) 35 | } 36 | 37 | return this 38 | -------------------------------------------------------------------------------- /src/io/wcm/devops/jenkins/pipeline/model/PatternMatchable.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.devops.jenkins.pipeline.model 21 | 22 | /** 23 | * Base model for Credentials and MangedFiles 24 | * 25 | * @see io.wcm.devops.jenkins.pipeline.credentials.Credential 26 | * @see io.wcm.devops.jenkins.pipeline.managedfiles.ManagedFile 27 | */ 28 | abstract class PatternMatchable implements Serializable { 29 | 30 | private static final long serialVersionUID = 1L 31 | 32 | String pattern = "" 33 | 34 | String id = "" 35 | 36 | /** 37 | * Constructor 38 | * 39 | * @param pattern The pattern to match against 40 | * @param id The id of the matchable item 41 | */ 42 | PatternMatchable(String pattern, String id) { 43 | this.pattern = pattern 44 | this.id = id 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/io/wcm/devops/jenkins/pipeline/managedfiles/ManagedFile.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.devops.jenkins.pipeline.managedfiles 21 | 22 | import com.cloudbees.groovy.cps.NonCPS 23 | import io.wcm.devops.jenkins.pipeline.model.PatternMatchable 24 | 25 | /** 26 | * Model for Jenkins managed files 27 | */ 28 | class ManagedFile extends PatternMatchable implements Serializable { 29 | 30 | private static final long serialVersionUID = 1L 31 | 32 | String name = "" 33 | 34 | String comment = "" 35 | 36 | ManagedFile(String pattern, String id, String name = null, String comment = null) { 37 | super(pattern, id) 38 | this.name = name 39 | this.comment = comment 40 | } 41 | 42 | @NonCPS 43 | boolean isValid() { 44 | return (pattern != null && id != null) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/vars/managedScripts/jobs/pipelineShellScript/shouldExecutePipelineShellScriptWithReturnStdoutTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.managedScripts.jobs.pipelineShellScript 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | /** 26 | * @return The script 27 | * @see vars.managedScripts.MangedPipelineShellScriptIT 28 | */ 29 | def execute() { 30 | CommandBuilder commandBuilder = new CommandBuilderImpl(this.steps) 31 | commandBuilder.addPathArgument('path/to/repo') 32 | commandBuilder.addArguments(['arg3','arg4']) 33 | return managedScripts.execPipelineShellScript('jenkins-pipeline-library/managedScripts/shell/maven/purge-snapshots.sh', commandBuilder, true, false) 34 | } 35 | 36 | return this 37 | -------------------------------------------------------------------------------- /test/vars/setupTools/jobs/shouldUseCustomEnvVarsTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.setupTools.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.model.Tool 23 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestContext 24 | 25 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 26 | 27 | /** 28 | * Runs the setupTools step with custom environment variables 29 | * 30 | * @return The script 31 | * @see vars.setupTools.SetupToolsIT 32 | */ 33 | def execute() { 34 | setupTools((TOOLS): [ 35 | [(TOOL_NAME): LibraryIntegrationTestContext.TOOL_JDK, (TOOL_TYPE): Tool.JDK, (TOOL_ENVVAR): "customJdkEnvVar"], 36 | [(TOOL_NAME): LibraryIntegrationTestContext.TOOL_MAVEN, (TOOL_TYPE): Tool.MAVEN, (TOOL_ENVVAR): "customMavenEnvVar"], 37 | ]) 38 | } 39 | 40 | return this 41 | -------------------------------------------------------------------------------- /vars/conditionalStage.md: -------------------------------------------------------------------------------- 1 | # conditionalStage 2 | 3 | The `conditionalStage` step allows you, as it says, to execute steps 4 | based on a condition when using the imperative pipeline. 5 | 6 | When the condition not evaluated to true the stage is skipped. 7 | 8 | The step uses the 9 | [`Utils`](https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/master/pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/Utils.groovy) 10 | from the pipeline-model-definition plugin to mark the stage as skipped. 11 | 12 | Sadly this call needs administrative script approval to work. 13 | 14 | #### `conditionalStage(String stageName, Boolean condition, Boolean throwException = true, Closure body)` 15 | 16 | Creates a stage with the name provided with `stageName`. 17 | 18 | When the `condition` is evaluated to `true` the body will be executed. 19 | 20 | When the `condition` is evaluated to `false` the body will not be 21 | executed and the stage is marked as skipped in the stages view. 22 | 23 | The optional parameter `throwException` controls the exception throw 24 | behavior. Set this parameter to false if you don't want to break the 25 | build when the call to the pipeline-model-definition `Utils` fails with 26 | a `RejectedAccessException` and you have no possibility to approve the 27 | rejected signature. 28 | 29 | **Example** 30 | ```groovy 31 | Boolean executeStage = true 32 | 33 | conditionalStage("stage", executeStage) { 34 | echo("hello world") 35 | } 36 | ``` 37 | -------------------------------------------------------------------------------- /test/io/wcm/testing/jenkins/pipeline/plugins/MattermostNotificationPluginMock.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.testing.jenkins.pipeline.plugins 21 | 22 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestContext 23 | 24 | import static io.wcm.testing.jenkins.pipeline.StepConstants.MATTERMOST_SEND 25 | import static io.wcm.testing.jenkins.pipeline.StepConstants.MQTT_NOTIFICATION 26 | import static io.wcm.testing.jenkins.pipeline.StepConstants.MQTT_NOTIFICATION 27 | 28 | class MattermostNotificationPluginMock { 29 | 30 | MattermostNotificationPluginMock(LibraryIntegrationTestContext context) { 31 | context.getPipelineTestHelper().registerAllowedMethod(MATTERMOST_SEND, [Map.class], { Map incomingCall -> context.getStepRecorder().record(MATTERMOST_SEND, incomingCall) }) 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /test/vars/managedScripts/jobs/pipelineShellScript/shouldExecutePipelineShellScriptWithReturnStdoutStatusTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.managedScripts.jobs.pipelineShellScript 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | /** 26 | * @return The script 27 | * @see vars.managedScripts.MangedPipelineShellScriptIT 28 | */ 29 | def execute() { 30 | CommandBuilder commandBuilder = new CommandBuilderImpl(this.steps) 31 | commandBuilder.addPathArgument('path/to/repo') 32 | commandBuilder.addArgument('argName', 'argValue') 33 | return managedScripts.execPipelineShellScript('jenkins-pipeline-library/managedScripts/shell/maven/purge-snapshots.sh', commandBuilder, true, true) 34 | } 35 | 36 | return this 37 | -------------------------------------------------------------------------------- /test/vars/notify/teams/jobs/notifyTeamsDisabledJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.notify.teams.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Runs notify.teams step with default configuration 26 | * 27 | * @return The script 28 | */ 29 | def execute() { 30 | notify.teams( 31 | [ 32 | (NOTIFY_TEAMS): [ 33 | (NOTIFY_TEAMS_ENABLED) : false, 34 | (NOTIFY_ON_SUCCESS) : true, 35 | (NOTIFY_ON_FAILURE) : true, 36 | (NOTIFY_ON_STILL_FAILING) : true, 37 | (NOTIFY_ON_FIXED) : true, 38 | (NOTIFY_ON_UNSTABLE) : true, 39 | (NOTIFY_ON_STILL_UNSTABLE) : true, 40 | (NOTIFY_ON_ABORT) : true, 41 | ] 42 | ] 43 | 44 | ) 45 | } 46 | 47 | 48 | return this 49 | -------------------------------------------------------------------------------- /test/vars/managedScripts/jobs/pipelineShellScript/shouldExecutePipelineShellScriptWithReturnStatusTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.managedScripts.jobs.pipelineShellScript 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilder 23 | import io.wcm.devops.jenkins.pipeline.shell.CommandBuilderImpl 24 | 25 | /** 26 | * @return The script 27 | * @see vars.managedScripts.MangedPipelineShellScriptIT 28 | */ 29 | def execute() { 30 | CommandBuilder commandBuilder = new CommandBuilderImpl(this.steps) 31 | commandBuilder.addPathArgument('path/to/repo') 32 | commandBuilder.addArgument('arg1') 33 | commandBuilder.addArgument('arg2') 34 | return managedScripts.execPipelineShellScript('jenkins-pipeline-library/managedScripts/shell/maven/purge-snapshots.sh', commandBuilder, false, true) 35 | } 36 | 37 | return this 38 | -------------------------------------------------------------------------------- /test/vars/notify/mattermost/jobs/notifyMattermostDisabledJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.notify.mattermost.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Runs notify.mattermost step with default configuration 26 | * 27 | * @return The script 28 | */ 29 | def execute() { 30 | notify.mattermost( 31 | [ 32 | (NOTIFY_MATTERMOST): [ 33 | (NOTIFY_MATTERMOST_ENABLED): false, 34 | (NOTIFY_ON_SUCCESS) : true, 35 | (NOTIFY_ON_FAILURE) : true, 36 | (NOTIFY_ON_STILL_FAILING) : true, 37 | (NOTIFY_ON_FIXED) : true, 38 | (NOTIFY_ON_UNSTABLE) : true, 39 | (NOTIFY_ON_STILL_UNSTABLE) : true, 40 | (NOTIFY_ON_ABORT) : true, 41 | ] 42 | ] 43 | 44 | ) 45 | } 46 | 47 | 48 | return this 49 | -------------------------------------------------------------------------------- /test/vars/sshAgentWrapper/jobs/shouldWrapWithCommandBuilderTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.sshAgentWrapper.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.shell.ScpCommandBuilderImpl 23 | import io.wcm.devops.jenkins.pipeline.ssh.SSHTarget 24 | import org.jenkinsci.plugins.workflow.cps.DSL 25 | 26 | /** 27 | * Runs the transferScp step with ssh credential auto lookup (key + username) 28 | * 29 | * @return The script 30 | * @see vars.setScmUrl.SetScmUrlIT 31 | */ 32 | def execute() { 33 | ScpCommandBuilderImpl commandBuilder = new ScpCommandBuilderImpl((DSL) this.steps) 34 | SSHTarget target = new SSHTarget("testserver1.testservers.domain.tld") 35 | sshAgentWrapper(target) { 36 | commandBuilder.setCredential(target.getCredential()) 37 | sh "echo 'with command builder'" 38 | } 39 | return commandBuilder 40 | } 41 | 42 | return this 43 | -------------------------------------------------------------------------------- /test/vars/wrappers/jobs/shouldWrapColorOnlyOnceWithSameColorModeTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.wrappers.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.utils.logging.LogLevel 23 | import io.wcm.devops.jenkins.pipeline.utils.logging.Logger 24 | 25 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 26 | 27 | /** 28 | * Runs the wrap.color step 29 | */ 30 | def execute() { 31 | Logger.init(this, LogLevel.DEBUG) 32 | Logger log = new Logger(this) 33 | 34 | Map config = [ 35 | (ANSI_COLOR): ANSI_COLOR_VGA 36 | ] 37 | 38 | log.info("non colorized output - 1") 39 | 40 | wrappers.color(config) { 41 | log.info("first wrap env.TERM: ${env.TERM}") 42 | wrappers.color(config) { 43 | log.info("second wrap env.TERM: ${env.TERM}") 44 | } 45 | } 46 | 47 | log.info("non colorized output - 2") 48 | } 49 | 50 | return this 51 | -------------------------------------------------------------------------------- /test/vars/setScmUrl/SetScmUrlIT.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.setScmUrl 21 | 22 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestBase 23 | import io.wcm.devops.jenkins.pipeline.environment.EnvironmentConstants 24 | import org.junit.Test 25 | 26 | import static org.junit.Assert.assertEquals 27 | 28 | class SetScmUrlIT extends LibraryIntegrationTestBase { 29 | 30 | @Test 31 | void shouldUseScmUrlFromConfig() { 32 | loadAndExecuteScript("vars/setScmUrl/jobs/setScmUrlWithConfigJob.groovy") 33 | assertEquals("http://domain.tld/group/project.git", this.getEnv(EnvironmentConstants.SCM_URL)) 34 | } 35 | 36 | @Test 37 | void shouldUseScmUrlFromShell() { 38 | loadAndExecuteScript("vars/setScmUrl/jobs/setScmUrlFromShellJob.groovy") 39 | assertEquals("http://remote.origin.url/group/project.git", this.getEnv(EnvironmentConstants.SCM_URL)) 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /test/vars/transferScp/jobs/transferScpSingleTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.transferScp.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Runs the transferScp step with ssh credential auto lookup (key + username) 26 | * 27 | * @return The script 28 | * @see vars.setScmUrl.SetScmUrlIT 29 | */ 30 | def execute() { 31 | transferScp( 32 | (SCP): [ 33 | (SCP_HOST) : "testserver1.testservers.domain.tld", 34 | (SCP_PORT) : null, 35 | (SCP_USER) : null, 36 | (SCP_ARGUMENTS) : [], 37 | (SCP_RECURSIVE) : false, 38 | (SCP_SOURCE) : "/path/to/source", 39 | (SCP_DESTINATION) : "/path/to/destination", 40 | (SCP_EXECUTABLE) : null, 41 | (SCP_HOST_KEY_CHECK): false 42 | ] 43 | ) 44 | } 45 | 46 | return this 47 | -------------------------------------------------------------------------------- /src/io/wcm/devops/jenkins/pipeline/utils/maps/MapMergeMode.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2019 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.devops.jenkins.pipeline.utils.maps 21 | /** 22 | * Enumeration class for map merge modes 23 | * 24 | * MapMergeMode.MERGE 25 | * - merges lists into a unique list ( [1,2] + [2,3] = [1,2,3] 26 | * - merges maps into a map with value overriding ([p1:v1, p2:v2] + [p3:v3, p2:v2changed] = [p1:v1, p2:v2changed, p3:v3]) 27 | * - merges values by overwriting the existing with the incoming 28 | * 29 | * MapMergeMode.SKIP 30 | * - keeps all overlapping keys in the existing map without modifying them 31 | * 32 | * MapMergeMode.REPLACE 33 | * - replaces all overlapping keys in the existing map with the incoming values 34 | */ 35 | enum MapMergeMode implements Serializable { 36 | 37 | MERGE(), 38 | SKIP(), 39 | REPLACE() 40 | 41 | private static final long serialVersionUID = 1L 42 | 43 | MapMergeMode() { 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/vars/im/teams/jobs/imTeamsConfigJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.im.teams.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.NOTIFY_TEAMS 23 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.NOTIFY_TEAMS_COLOR 24 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.NOTIFY_TEAMS_MESSAGE 25 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.NOTIFY_TEAMS_WEBHOOK_URL 26 | 27 | /** 28 | * Runs im.teams step with default configuration 29 | * 30 | * @return The script 31 | */ 32 | def execute() { 33 | Map config = [ 34 | (NOTIFY_TEAMS): [ 35 | (NOTIFY_TEAMS_MESSAGE) : "configMessage", 36 | (NOTIFY_TEAMS_WEBHOOK_URL) : "configWebhookUrl", 37 | (NOTIFY_TEAMS_COLOR) : "configColor", 38 | ] 39 | ] 40 | 41 | im.teams(config) 42 | } 43 | 44 | 45 | return this 46 | -------------------------------------------------------------------------------- /test/vars/wrappers/jobs/shouldWrapColorMultiWithConfigTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.wrappers.jobs 21 | 22 | import io.wcm.devops.jenkins.pipeline.utils.logging.LogLevel 23 | import io.wcm.devops.jenkins.pipeline.utils.logging.Logger 24 | 25 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 26 | 27 | /** 28 | * Runs the wrap.color step 29 | */ 30 | def execute() { 31 | Logger.init(this, LogLevel.DEBUG) 32 | Logger log = new Logger(this) 33 | 34 | Map config = [ 35 | (ANSI_COLOR): ANSI_COLOR_GNOME_TERMINAL 36 | ] 37 | 38 | log.info("non colorized output - 1") 39 | 40 | wrappers.color(config) { 41 | config[ANSI_COLOR] = ANSI_COLOR_VGA 42 | log.info("first wrap env.TERM: ${env.TERM}") 43 | wrappers.color(config) { 44 | log.info("second wrap env.TERM: ${env.TERM}") 45 | } 46 | } 47 | 48 | log.info("non colorized output - 2") 49 | } 50 | 51 | return this 52 | -------------------------------------------------------------------------------- /test/vars/transferScp/jobs/transferScpRecursiveTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.transferScp.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Runs the setScmUrl step in auto detection mode where scm url is determined via command line 26 | * 27 | * @return The script 28 | * @see vars.setScmUrl.SetScmUrlIT 29 | */ 30 | def execute() { 31 | transferScp( 32 | (SCP): [ 33 | (SCP_HOST) : "subdomain.domain.tld", 34 | (SCP_PORT) : 2222, 35 | (SCP_USER) : "testuser", 36 | (SCP_ARGUMENTS) : ["-C", "-4"], 37 | (SCP_RECURSIVE) : true, 38 | (SCP_SOURCE) : "'/path/to/recursive source/*'", 39 | (SCP_DESTINATION) : "'/path/to/recursive destination'", 40 | (SCP_EXECUTABLE) : "/usr/bin/scp", 41 | (SCP_HOST_KEY_CHECK): true 42 | ] 43 | ) 44 | } 45 | 46 | return this 47 | -------------------------------------------------------------------------------- /test/vars/setBuildName/SetBuildNameIT.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.setBuildName 21 | 22 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestBase 23 | import org.junit.Test 24 | 25 | import static org.junit.Assert.assertEquals 26 | 27 | class SetBuildNameIT extends LibraryIntegrationTestBase { 28 | 29 | @Test 30 | void shouldUseGitBranch() { 31 | this.setEnv("BUILD_NUMBER", "1") 32 | this.setEnv("GIT_BRANCH", "I_AM_THE_GITBRANCH") 33 | loadAndExecuteScript("vars/setBuildName/jobs/setBuildNameJob.groovy") 34 | 35 | assertEquals("#1_I_AM_THE_GITBRANCH", this.context.getRunWrapperMock().getDisplayName()) 36 | } 37 | 38 | @Test 39 | void shouldNotUseGitBranch() { 40 | this.setEnv("BUILD_NUMBER", "1") 41 | this.setEnv("GIT_BRANCH", null) 42 | loadAndExecuteScript("vars/setBuildName/jobs/setBuildNameJob.groovy") 43 | 44 | assertEquals("#1", this.context.getRunWrapperMock().getDisplayName()) 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /test/vars/execMaven/jobs/execMavenCustomVariant2Job.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMaven.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Runs execMaven step with custom configuration where goals, defines and arguments are represented by strings 26 | * 27 | * @return The script 28 | * @see vars.execMaven.ExecMavenIT 29 | */ 30 | def execute() { 31 | execMaven( 32 | (SCM): [(SCM_URL): "https://subdomain.domain-new.tld/group/project1.git"], 33 | (MAVEN): [ 34 | (MAVEN_POM) : "path/to/customPom2.xml", 35 | (MAVEN_GOALS) : "customGoal3 customGoal4", 36 | (MAVEN_DEFINES) : "-DdefineValue2=true -DdefineFlag2", 37 | (MAVEN_GLOBAL_SETTINGS): "CUSTOM_GLOBAL_SETTINGS_VARIANT2", 38 | (MAVEN_SETTINGS) : "CUSTOM_SETTINGS_VARIANT2", 39 | (MAVEN_ARGUMENTS) : "-B -U" 40 | ] 41 | ) 42 | } 43 | 44 | return this 45 | -------------------------------------------------------------------------------- /test/vars/notify/teams/jobs/notifyTeamsCustomJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2020 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.notify.teams.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Runs notify.teams step with default configuration 26 | * 27 | * @return The script 28 | */ 29 | def execute() { 30 | Map config = [ 31 | (NOTIFY_TEAMS) : [ 32 | (NOTIFY_TEAMS_ENABLED) : true, 33 | (NOTIFY_TEAMS_MESSAGE) : "customMessage", 34 | (NOTIFY_TEAMS_WEBHOOK_URL): "https://customWebhookUrl", 35 | (NOTIFY_TEAMS_COLOR) : "customColor", 36 | (NOTIFY_ON_SUCCESS) : true, 37 | (NOTIFY_ON_FAILURE) : false, 38 | (NOTIFY_ON_STILL_FAILING) : false, 39 | (NOTIFY_ON_FIXED) : false, 40 | (NOTIFY_ON_UNSTABLE) : false, 41 | (NOTIFY_ON_STILL_UNSTABLE): false, 42 | (NOTIFY_ON_ABORT) : true, 43 | ] 44 | ] 45 | notify.teams(config) 46 | } 47 | 48 | return this 49 | -------------------------------------------------------------------------------- /test/vars/execMaven/jobs/execMavenCustomVariant1Job.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMaven.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Runs execMaven step with custom configuration where goals, defines and arguments are represented by a list 26 | * 27 | * @return The script 28 | * @see vars.execMaven.ExecMavenIT 29 | */ 30 | def execute() { 31 | execMaven( 32 | (SCM): [(SCM_URL): "https://subdomain.domain-new.tld/group/project1.git"], 33 | (MAVEN): [ 34 | (MAVEN_POM) : "path/to/customPom1.xml", 35 | (MAVEN_GOALS) : ["customGoal1", "customGoal2"], 36 | (MAVEN_DEFINES) : ["defineValue1": true, "defineFlag1": null], 37 | (MAVEN_GLOBAL_SETTINGS): "CUSTOM_GLOBAL_SETTINGS_VARIANT1", 38 | (MAVEN_SETTINGS) : "CUSTOM_SETTINGS_VARIANT1", 39 | (MAVEN_ARGUMENTS) : ["-B", "-U"] 40 | ] 41 | ) 42 | } 43 | 44 | return this 45 | -------------------------------------------------------------------------------- /vars/jenkinsRestApi.md: -------------------------------------------------------------------------------- 1 | # jenkinsRestApi 2 | 3 | Utility functions for Jenkins REST API. 4 | 5 | # Table of contents 6 | 7 | * [`findJobsByNameRegex(Map remote)`](#list-job-findjobsbynameregexmap-remote) 8 | * [Input](#input) 9 | * [Example](#example) 10 | * [Related classes](#related-classes) 11 | 12 | ## `List findJobsByNameRegex(Map remote)` 13 | 14 | This function will retrieve and return all matching Jobs from a Jenkins 15 | instance. 16 | 17 | ### Input 18 | 19 | | Key | Type | Description | 20 | |:--------------|:-------------------------|:-----------------------------------------------------------------------------| 21 | | regex | String, **Mandatory** | The regular expression the job name must match to | 22 | | baseUrl | String, **Mandatory** | The baseUrl of the remove jenkins instance | 23 | | credentialsId | String, **Mandatory** | The id of the credentials to use for authentication on remote | 24 | | depth | Integer, defaults to `3` | The maximum depth to retrieve when Cloudbees Folder Plugin is used on remote | 25 | 26 | ### Example 27 | 28 | ```groovy 29 | import io.wcm.devops.jenkins.pipeline.model.jenkins.api.Job 30 | 31 | Map remote = [ 32 | regex: ".*", 33 | baseUrl: "https://jenkins.example.org", 34 | credentialsId: "org.example.jenkins.credentials", 35 | depth: 4 36 | ] 37 | 38 | List foundJobs = jenkinsRestApi.findJobsByNameRegex(remote) 39 | ``` 40 | 41 | ## Related classes 42 | * [`Job`](../src/io/wcm/devops/jenkins/pipeline/model/jenkins/api/Job.groovy) 43 | -------------------------------------------------------------------------------- /vars/wrappers.md: -------------------------------------------------------------------------------- 1 | # wrappers 2 | 3 | This part of the library contains utilites for wrappers such as 4 | * ansiColor 5 | 6 | # Table of contents 7 | 8 | * [`color(Map config, Closure body)`](#colormap-config-closure-body) 9 | * [`color` Example](#color-example) 10 | 11 | ## `color(Map config, Closure body)` 12 | 13 | This step is just a small adapter for the `ansiColor` step. 14 | It uses the pipeline configuration to set the color mode 15 | 16 | ### `color` Example 17 | 18 | ```groovy 19 | import io.wcm.devops.jenkins.pipeline.utils.logging.LogLevel 20 | import io.wcm.devops.jenkins.pipeline.utils.logging.Logger 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | Map config = [ 24 | (ANSI_COLOR) : ANSI_COLOR_XTERM 25 | ] 26 | 27 | Logger.init(this, LogLevel.INFO) 28 | Logger log = new Logger(this) 29 | wrappers.color(config) { 30 | log.info("i have a colorized loglevel!") 31 | } 32 | 33 | ``` 34 | 35 | ### Configuration options 36 | 37 | The step has only one configuration option: `ConfigConstants.ANSI_COLOR`. 38 | The value used in this configuration option is the color mode provided to the 39 | `ansiColor` Step 40 | 41 | ```groovy 42 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 43 | 44 | wrappers.color( 45 | (ANSI_COLOR): ANSI_COLOR_XTERM 46 | ) 47 | ``` 48 | 49 | Available values: 50 | * `ConfigConstants.ANSI_COLOR_XTERM` 51 | * `ConfigConstants.ANSI_COLOR_GNOME_TERMINAL` 52 | * `ConfigConstants.ANSI_COLOR_VGA` 53 | * `ConfigConstants.ANSI_COLOR_CSS` 54 | 55 | ## Related classes: 56 | * [`Logger`](../src/io/wcm/devops/jenkins/pipeline/utils/logging/Logger.groovy) 57 | * [`LogLevel`](../src/io/wcm/devops/jenkins/pipeline/utils/logging/LogLevel.groovy) 58 | -------------------------------------------------------------------------------- /test/vars/execMaven/jobs/execMavenWithBuildParametersTestJob.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.execMaven.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.MAVEN 23 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.MAVEN_GOALS 24 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.MAVEN_INJECT_PARAMS 25 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM 26 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.SCM_URL 27 | 28 | /** 29 | * Runs execMaven step with default configuration to test auto lookup for global and local maven settings 30 | * 31 | * @return The script 32 | * @see vars.execMaven.ExecMavenIT 33 | */ 34 | def execute() { 35 | execMaven( 36 | (SCM): [ 37 | (SCM_URL): "https://subdomain.evenbetterdomain.tld/group3/project1.git" 38 | ], 39 | (MAVEN): [ 40 | (MAVEN_GOALS) : ["clean", "verify"], 41 | (MAVEN_INJECT_PARAMS): true 42 | ] 43 | ) 44 | } 45 | 46 | return this 47 | -------------------------------------------------------------------------------- /test/vars/checkoutScm/jobs/checkoutScmCustomVariant1Job.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package vars.checkoutScm.jobs 21 | 22 | import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.* 23 | 24 | /** 25 | * Executes a custom checkout with all supported configuration options that should not use the provided credentialsId 26 | * 27 | * @return The script 28 | * @see vars.checkoutScm.CheckoutScmIT 29 | */ 30 | def execute() { 31 | checkoutScm((SCM): [ 32 | (SCM_URL) : "git@git-ssh.betterdomain.tld/group/project1.git", 33 | (SCM_CREDENTIALS_ID) : 'CUSTOM_CREDENTIAL_ID', 34 | (SCM_BRANCHES) : [[name: 'customBranch']], 35 | (SCM_DO_GENERATE_SUBMODULE_CONFIGURATION): true, 36 | (SCM_EXTENSIONS) : [[$class: 'CleanBeforeCheckout'], [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], 37 | (SCM_SUBMODULE_CONFIG) : [[$class: 'CustomSubModuleCfg']] 38 | ]) 39 | } 40 | 41 | return this 42 | -------------------------------------------------------------------------------- /src/io/wcm/devops/jenkins/pipeline/model/jenkins/api/Job.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2019 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.devops.jenkins.pipeline.model.jenkins.api 21 | 22 | import io.wcm.devops.jenkins.pipeline.utils.logging.Logger 23 | 24 | /** 25 | * Job Model for Jenkins REST API. 26 | */ 27 | class Job implements Serializable { 28 | 29 | Logger log = new Logger(this) 30 | 31 | private static final long serialVersionUID = 1L 32 | 33 | String name 34 | 35 | String url 36 | 37 | String _class 38 | 39 | List jobs 40 | 41 | Map data 42 | 43 | Job(Map data) { 44 | this.data = data 45 | this.url = data.url ?: null 46 | this.name = data.name ?: null 47 | this._class = data._class ?: null 48 | this.jobs = [] 49 | List rawJobs = data.jobs ?: [] 50 | for (Map rawJobData in rawJobs) { 51 | Job job = new Job(rawJobData) 52 | this.jobs.push(job) 53 | } 54 | } 55 | 56 | List flatten() { 57 | List ret = [this] 58 | for (Job job in jobs) { 59 | ret += job.flatten() 60 | } 61 | return ret 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /test/io/wcm/testing/jenkins/pipeline/plugins/AnsiColorPluginMock.groovy: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * wcm.io 4 | * %% 5 | * Copyright (C) 2017 - 2018 wcm.io DevOps 6 | * %% 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * #L% 19 | */ 20 | package io.wcm.testing.jenkins.pipeline.plugins 21 | 22 | import io.wcm.testing.jenkins.pipeline.LibraryIntegrationTestContext 23 | 24 | import static io.wcm.testing.jenkins.pipeline.StepConstants.ANSI_COLOR 25 | 26 | class AnsiColorPluginMock { 27 | 28 | LibraryIntegrationTestContext context 29 | 30 | AnsiColorPluginMock(LibraryIntegrationTestContext context) { 31 | this.context = context 32 | 33 | context.getPipelineTestHelper().registerAllowedMethod(ANSI_COLOR, [String.class, Closure.class], ansiColorCallback) 34 | } 35 | 36 | /** 37 | * Mocks the 'configFileProvider' step. For each ManagedFile the environment variable is set to a dummy filepath 38 | */ 39 | def ansiColorCallback = { 40 | String colorMode, Closure body -> 41 | context.getStepRecorder().record(ANSI_COLOR, colorMode) 42 | this.context.getEnvVars().setProperty('TERM', colorMode) 43 | body.run() 44 | this.context.getEnvVars().setProperty('TERM', null) 45 | } 46 | 47 | } 48 | --------------------------------------------------------------------------------