├── .gitignore ├── CHANGELOG.md ├── Jenkinsfile ├── Makefile ├── README.md ├── checksyntax ├── Makefile └── check_syntax.sh ├── init-jfr-test-framework.inc ├── src ├── cwp │ └── custom-war-packager.inc ├── hooks │ ├── logs.inc │ ├── result.inc │ └── workspace.inc ├── jfr │ └── jenkinsfile-runner.inc └── utilities │ ├── timeout.inc │ └── utils.inc └── tests ├── Makefile ├── test_resources ├── test_all_hooks │ ├── Jenkinsfile │ └── packager-config.yml ├── test_failing_docker_image │ └── packager-config.yml ├── test_jenkinsfile_fail │ ├── Jenkinsfile │ └── packager-config.yml ├── test_jenkinsfile_unstable │ ├── Jenkinsfile │ └── packager-config.yml ├── test_timeout │ └── Jenkinsfile ├── test_with_default_tag │ └── packager-config.yml ├── test_with_default_tag_using_cwp_docker_image │ └── packager-config.yml ├── test_with_jfr_options │ ├── Jenkinsfile │ └── packager-config.yml ├── test_with_tag │ ├── Jenkinsfile │ └── packager-config.yml └── test_with_tag_using_cwp_docker_image │ ├── Jenkinsfile │ └── packager-config.yml ├── tests.sh ├── timeout-tests.sh └── workspace_hook_tests.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vscode/ 3 | out 4 | .cwp-build/ 5 | tests/.testing 6 | checksyntax/.checksyntax/ 7 | .shunit2/ 8 | *.log 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | Currently there's no released distribution 4 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | /* Only keep the 10 most recent builds. */ 2 | properties([[$class: 'BuildDiscarderProperty', 3 | strategy: [$class: 'LogRotator', numToKeepStr: '10']]]) 4 | 5 | node { 6 | stage('checkout') { 7 | deleteDir() 8 | checkout scm 9 | } 10 | 11 | stage('shellcheck') { 12 | dir('jenkinsfile-runner-test-framework') { 13 | global_check_result=0 14 | current_directory="${WORKSPACE}/jenkinsfile-runner-test-framework" 15 | def incFiles=findFiles(glob: '**/*.inc') 16 | incFiles.each{ 17 | if("${it}".lastIndexOf("/") == -1) { 18 | output_file="${it}.json" 19 | } else { 20 | output_file="${it}".substring("${it}".lastIndexOf("/")+1) + ".json" 21 | } 22 | result=sh (script: "docker run -v $current_directory:/mnt koalaman/shellcheck:stable -f json ${it} > $output_file", returnStatus: true) 23 | if(result) { 24 | global_check_result++ 25 | } 26 | } 27 | if(global_check_result > 0) { 28 | echo "One or more scripts have an invalid sintaxis" 29 | currentBuild.result = 'UNSTABLE' 30 | archiveArtifacts artifacts: '**/*.inc.json' 31 | } 32 | } 33 | } 34 | 35 | stage('testing') { 36 | dir('jenkinsfile-runner-test-framework') { 37 | result=sh (script: 'make test', returnStatus: true) != 0 38 | if(result) { 39 | echo "Test failures!" 40 | currentBuild.result = 'FAILED' 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Main makefile for the testing framework. It should be executed by the actual project containing the tests 2 | .PHONY: init 3 | 4 | init: 5 | rm -rf .shunit2 6 | # avoid any cache of checks/tests 7 | rm -rf tests/.testing 8 | rm -rf checksyntax/.checksyntax 9 | # TODO So far, the released tags do not contains all the macros and functions that 10 | # master branch does (assertContains, e.g.). Once a new version containing all 11 | # the functionalyty is released we should clone using --branch 12 | git clone https://github.com/kward/shunit2 .shunit2 && cd .shunit2 && git checkout abb3ab2fef8c549933e378ae3d12127dfc748e73 13 | 14 | test: 15 | $(MAKE) -C tests 16 | 17 | syntax: 18 | $(MAKE) -C checksyntax 19 | 20 | verify: syntax test 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jenkinsfile Runner Test Framework 2 | This repository provides a test harness for verifying Jenkinsfile Runner Docker images. That image can be already built or it can be built using Custom War Packager and the set of utility functions provided by the framework. 3 | 4 | The framework takes a Jenkinsfile from a directory and runs against the image, waiting for its completion, and then verifies log outputs and results. 5 | 6 | [CHANGELOG](./CHANGELOG.md) 7 | 8 | ## Technical requirements 9 | The test suite is designed to run on Linux, targeting JFR execution only in Docker containers. 10 | It relies on shUnit2 and its hooks allow to check the log outputs, the content in the workspace and the result of the execution in an easy way. 11 | 12 | In case it's desired to build the docker image using the [Custom War Packager](https://github.com/jenkinsci/custom-war-packager) it is possible to specify a particular version (released, timestamped snapshot or incremental), although the framework defines a default version. 13 | 14 | The test framework supports timeouts (_in progress at the time of writing this README file_) and `JAVA_OPTS` environment variable. 15 | 16 | ## Usage 17 | ### Enable the framework 18 | To make use of the test framework we have to download the scripts cloning the repository or downloading the sources. Then execute the Makefile provided by the framework. An example might be: 19 | 20 | ``` 21 | # Basic Makefile example 22 | .PHONY: all 23 | 24 | all: clean init test 25 | 26 | clean: 27 | # Avoid to cache the framework 28 | rm -rf jenkinsfile-runner-test-framework 29 | 30 | init: 31 | # Retrieve the test framework. In this case, we are cloning the repository 32 | git clone --depth 1 https://github.com/jenkinsci/jenkinsfile-runner-test-framework 33 | $(MAKE) -C jenkinsfile-runner-test-framework 34 | 35 | test: 36 | # Execute your tests here 37 | ``` 38 | 39 | The Makefile to init the framework will download the shUnit2 library so any project/developer making use of this framework can disregard that step 40 | 41 | ### Init the framework in the test script 42 | 43 | Jenkinsfile Runner Test Framework unifies all the global configuration and the files to include in a single script `init-jfr-test-framework.inc`, so we just have to invoke and load it. 44 | 45 | ``` 46 | test_framework_directory="path_to_jenkinsfile_runner_test_framework" 47 | 48 | . $test_framework_directory/init-jfr-test-framework.inc 49 | ``` 50 | 51 | Once the test framework is loaded, all the functions will be available as any other shell script function. 52 | 53 | ``` 54 | test_example_that_download_CWP_jar_generate_docker_image_and_run_jenkinsfile() { 55 | downloaded_cwp_jar=$(download_cwp "$test_framework_directory") 56 | 57 | jfr_tag=$(execute_cwp_jar_and_generate_docker_image "$test_framework_directory" "$downloaded_cwp_jar" "$version" "path_to/packager-config.yml" "$jenkinsfile_runner_tag" | grep 'Successfully tagged') 58 | 59 | execution_should_success "$?" "$jfr_tag" "$jenkinsfile_runner_tag" 60 | 61 | result=$(run_jfr_docker_image "$jenkinsfile_runner_tag" "path_to/Jenkinsfile") 62 | 63 | jenkinsfile_execution_should_succeed "$?" "$result" 64 | } 65 | ``` 66 | 67 | The last step is to init all the framework invoking the `init_framework` function, which is defined in the `init-jfr-test-framework.inc` script. This function *must be invoked at the end of the test shell script so shUnit2 is loaded properly*. 68 | 69 | ## Contributing 70 | In case someone is interested on contributing, the Jenkinsfile Runner Test Framework gives the opportunity to check any change: 71 | 72 | * In case the contributor would like to check the syntax of the scripts, it's enough to execute `make syntax` 73 | * In case the desire is to execute the smoke tests, the execution command is `make test` 74 | * The recommendation is to check and verify both texts and syntax. In that case, just execute `make verify` 75 | 76 | ## Further reading 77 | 78 | * [Jenkinsfile Runner](https://github.com/jenkinsci/jenkinsfile-runner/) 79 | * [A unit test framework for shell scripts](https://github.com/kward/shunit2) 80 | -------------------------------------------------------------------------------- /checksyntax/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile to check the syntax of the scripts 2 | .PHONY: syntax 3 | 4 | syntax: 5 | $(shell pwd)/check_syntax.sh 6 | -------------------------------------------------------------------------------- /checksyntax/check_syntax.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Path to this source file 5 | export parent_directory=$(dirname "$(pwd)") 6 | export check_directory="$parent_directory/checksyntax/.checksyntax" 7 | 8 | process_inc_file() { 9 | echo "Checking $1" 10 | output_file="$check_directory/${1##*/}.gcc" 11 | docker run -v "$parent_directory":/mnt koalaman/shellcheck:stable -f gcc "$1" > "$output_file" 12 | result=$(cat "$output_file") 13 | if [ -z "$result" ] 14 | then 15 | rm "$output_file" 16 | else 17 | echo "$result" 18 | fi 19 | echo "" 20 | } 21 | 22 | cd "$parent_directory" 23 | rm -rf "$check_directory" 24 | mkdir -p "$check_directory" 25 | 26 | export -f process_inc_file 27 | find . -name '*.inc' -exec bash -c 'process_inc_file {}' \; 28 | 29 | echo "[INFO] A copy of the results can be found at $check_directory" 30 | echo "" 31 | -------------------------------------------------------------------------------- /init-jfr-test-framework.inc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Path to this source file, stored in BASH_SOURCE 5 | root_directory=$(dirname "${BASH_SOURCE[0]}") 6 | sources="$root_directory/src" 7 | sh_unit_directory="$root_directory/.shunit2" 8 | timeout_test_file="/tmp/with_timeout.sh" 9 | export DEFAULT_CWP_VERSION="1.5" 10 | 11 | if [ ! -d "$sh_unit_directory" ] 12 | then 13 | if [ -z "$1" ] || [ ! -d "$1" ] 14 | then 15 | echo "[ERROR] shUnit2 has not been properly initialized" 16 | exit 1 17 | else 18 | sh_unit_directory="$1" 19 | fi 20 | fi 21 | 22 | # shellcheck source=src/utilities/utils.inc 23 | . "$sources"/utilities/utils.inc 24 | # shellcheck source=src/utilities/timeout.inc 25 | . "$sources"/utilities/timeout.inc 26 | # shellcheck source=src/hooks/logs.inc 27 | . "$sources"/hooks/logs.inc 28 | # shellcheck source=src/hooks/result.inc 29 | . "$sources"/hooks/result.inc 30 | # shellcheck source=src/hooks/workspace.inc 31 | . "$sources"/hooks/workspace.inc 32 | # shellcheck source=src/cwp/custom-war-packager.inc 33 | . "$sources"/cwp/custom-war-packager.inc 34 | # shellcheck source=src/jfr/jenkinsfile-runner.inc 35 | . "$sources"/jfr/jenkinsfile-runner.inc 36 | 37 | 38 | search_tests() { 39 | 40 | # Extract the lines with test function names, strip of anything besides the 41 | # function name, and output everything on a single line. 42 | test_regex='^\s*((function test[A-Za-z0-9_-]*)|(test[A-Za-z0-9_-]* *\(\)))' 43 | # shellcheck disable=SC2196 44 | egrep "${test_regex}" "$0" \ 45 | |sed 's/^[^A-Za-z0-9_-]*//;s/^function //;s/\([A-Za-z0-9_-]*\).*/\1/g' \ 46 | |xargs 47 | 48 | } 49 | 50 | # Override the suite test to execute the tests with timeout if applies 51 | suite() { 52 | 53 | tests=$(search_tests) 54 | for name in ${tests}; do 55 | new_test=$(create_test_with_template "$name" "$timeout_test_file") 56 | suite_addTest "$new_test" 57 | done 58 | # shellcheck disable=SC1090 59 | . $timeout_test_file 60 | 61 | } 62 | 63 | init_framework() { 64 | create_test_file "$timeout_test_file" 65 | # shellcheck disable=SC1090 66 | . "$sh_unit_directory/shunit2" 67 | } 68 | -------------------------------------------------------------------------------- /src/cwp/custom-war-packager.inc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # function to download the CWP jar 5 | # $1: Working directory 6 | # $2: CWP version to use. Optional 7 | download_cwp() { 8 | 9 | if [ "$#" -ge 1 ] 10 | then 11 | if [ "$#" -eq 2 ] 12 | then 13 | version_to_download="$2" 14 | else 15 | version_to_download="$DEFAULT_CWP_VERSION" 16 | fi 17 | 18 | cwp_jar_file="$1/.cwp-build/cwp-cli-$version_to_download.jar" 19 | 20 | rm -rf "$1/.cwp-build" 21 | mkdir -p "$1/.cwp-build" 22 | 23 | if [[ $version_to_download == *"SNAPSHOT"* ]] 24 | then 25 | wget -O "$cwp_jar_file" https://repo.jenkins-ci.org/snapshots/io/jenkins/tools/custom-war-packager/custom-war-packager-cli/"$version_to_download"/custom-war-packager-cli-"$version_to_download"-jar-with-dependencies.jar 26 | else 27 | if [[ $2 == *"rc"* ]] 28 | then 29 | wget -O "$cwp_jar_file" https://repo.jenkins-ci.org/incrementals/io/jenkins/tools/custom-war-packager/custom-war-packager-cli/"$version_to_download"/custom-war-packager-cli-"$version_to_download"-jar-with-dependencies.jar 30 | else 31 | wget -O "$cwp_jar_file" https://repo.jenkins-ci.org/releases/io/jenkins/tools/custom-war-packager/custom-war-packager-cli/"$version_to_download"/custom-war-packager-cli-"$version_to_download"-jar-with-dependencies.jar 32 | fi 33 | fi 34 | 35 | downloaded=$(du -k "$cwp_jar_file" | cut -f1) 36 | if [ "$downloaded" == "0" ] 37 | then 38 | echo "CWP jar not found" 39 | return 1 40 | else 41 | echo "$cwp_jar_file" 42 | return 0 43 | fi 44 | else 45 | echo "Error. Missing parameters:" 46 | echo " Working directory" 47 | echo " (Optional) CWP version to use. ${DEFAULT_CWP_VERSION} by default" 48 | return 1 49 | fi 50 | 51 | } 52 | 53 | # function to execute a CWP downloaded jar 54 | # $1: Working directory 55 | # $2: Path to cwp.jar 56 | # $3: Jenkins version 57 | # $4: Path to packager config file 58 | execute_cwp_jar() { 59 | 60 | if [ "$#" -gt 3 ] 61 | then 62 | java -jar "$2" -configPath "$4" -tmpDir "$1/out/tmp/" -version "$3" 63 | return 0 64 | else 65 | echo "Error. Missing parameters:" 66 | echo " Working directory" 67 | echo " Path to cwp.jar" 68 | echo " Jenkins version" 69 | echo " Path to packager config file" 70 | return 1 71 | fi 72 | 73 | } 74 | 75 | # function to generate the docker image using CWP using a downloaded jar 76 | # $1: Working directory 77 | # $2: Path to cwp.jar 78 | # $3: Jenkins version 79 | # $4: Path to packager config file 80 | # $5: Tag for the docker image. "jenkins-experimental/${TEST_NAME}" by default or 81 | # "jenkins-experimental/jenkinsfile-runner-test" if it is run from a setUp function 82 | execute_cwp_jar_and_generate_docker_image() { 83 | 84 | if [ "$#" -gt 3 ] 85 | then 86 | if [ "$#" -eq 5 ] 87 | then 88 | image_tag="$5" 89 | else 90 | # shellcheck disable=SC2154 91 | test_name="${_shunit_test_}" 92 | if [ -z "$test_name" ] 93 | then 94 | image_tag="jenkins-experimental/jenkinsfile-runner-test" 95 | else 96 | image_tag="jenkins-experimental/$test_name" 97 | fi 98 | fi 99 | 100 | if execute_cwp_jar "$1" "$2" "$3" "$4" 101 | then 102 | docker build -t "$image_tag" -f "$1/out/tmp/output/Dockerfile" "$1/out/tmp/output/" 103 | return 0 104 | else 105 | return 1 106 | fi 107 | else 108 | echo "Error. Missing parameters:" 109 | echo " Working directory" 110 | echo " Path to cwp.jar" 111 | echo " Jenkins version" 112 | echo " Path to packager config file" 113 | echo " (Optional) Tag for the docker image. 'jenkins-experimental/TEST_NAME' by default or 'jenkins-experimental/jenkinsfile-runner-test' if it is run from a setUp function" 114 | return 1 115 | fi 116 | 117 | } 118 | 119 | # function to generate the docker image using CWP downloading a downloaded jar 120 | # $1: Working directory 121 | # $2: CWP version to use 122 | # $3: Jenkins version 123 | # $4: Path to packager config file 124 | # $5: Tag for the docker image. "jenkins-experimental/${TEST_NAME}" by default or 125 | # "jenkins-experimental/jenkinsfile-runner-test" if it is run from a setUp function 126 | download_execute_and_generate_docker_image_with_cwp() { 127 | 128 | if [ "$#" -gt 3 ] 129 | then 130 | cwp_jar_file=$(download_cwp "$1" "$2") 131 | if execute_cwp_jar_and_generate_docker_image "$1" "$cwp_jar_file" "$3" "$4" "$5" 132 | then 133 | return 0 134 | else 135 | return 1 136 | fi 137 | else 138 | echo "Error. Missing parameters:" 139 | echo " Working directory" 140 | echo " Path to cwp.jar" 141 | echo " Jenkins version" 142 | echo " Path to packager config file" 143 | echo " (Optional) Tag for the docker image. 'jenkins-experimental/TEST_NAME' by default or 'jenkins-experimental/jenkinsfile-runner-test' if it is run from a setUp function" 144 | return 1 145 | fi 146 | 147 | } 148 | 149 | # function to generate the docker image using the CWP docker image 150 | # $2: Path to packager config file 151 | # $3: Tag for the docker image. "jenkins-experimental/${TEST_NAME}" by default or 152 | # "jenkins-experimental/jenkinsfile-runner-test" if it is run from a setUp function 153 | generate_docker_image_from_cwp_docker_image() { 154 | 155 | if [ "$#" -ge 1 ] 156 | then 157 | if [ "$#" -eq 2 ] 158 | then 159 | image_tag="$2" 160 | else 161 | if [ -z "${_shunit_test_}" ] 162 | then 163 | image_tag="jenkins-experimental/jenkinsfile-runner-test" 164 | else 165 | image_tag="jenkins-experimental/${_shunit_test_}" 166 | fi 167 | fi 168 | 169 | if [ -z "${_shunit_test_}" ] 170 | then 171 | # In case this function is not invoked from the test but from a setUp/tearDown function 172 | work_directory="/tmp/.cwp-docker" 173 | else 174 | work_directory="/tmp/${_shunit_test_}/.cwp-docker" 175 | fi 176 | 177 | mkdir -p "$work_directory" 178 | mkdir -p "$work_directory/tmp" 179 | 180 | docker run --rm -v "$work_directory/tmp":/tmp -v "$1":/sources/packager-config.yml jenkins/custom-war-packager -configPath /sources/packager-config.yml -tmpDir /tmp/app 181 | docker build -t "$image_tag" -f "$work_directory/tmp/app/output/Dockerfile" "$work_directory/tmp/app/output" 182 | return 0 183 | else 184 | echo "Error. Missing parameters:" 185 | echo " Path to packager config file" 186 | echo " (Optional) Tag for the docker image. 'jenkins-experimental/TEST_NAME' by default or 'jenkins-experimental/jenkinsfile-runner-test' if it is run from a setUp function" 187 | return 1 188 | fi 189 | 190 | } 191 | -------------------------------------------------------------------------------- /src/hooks/logs.inc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Check if the execution log of some command contains an expected pattern 5 | # $1: Expected contained value 6 | # $2: (Optional) Logs from the test or returned message 7 | logs_contains() { 8 | 9 | if [ "$#" -ge 1 ] 10 | then 11 | test_name=$(get_test_name_message) 12 | 13 | if [ "$#" -eq 2 ] 14 | then 15 | assertContains "$test_name should contain '$1'" "$2" "$1" 16 | return 0 17 | elif [ -e "${_shunit_test_}.log" ] 18 | then 19 | text_contained=0 20 | if [[ "$(cat ${_shunit_test_}.log)" == *"$1"* ]]; then 21 | text_contained=1 22 | fi 23 | 24 | assertEquals "$test_name should contain '$1'" "1" "$text_contained" 25 | return 0 26 | else 27 | echo "Error. No log to inspect" 28 | return 1 29 | fi 30 | else 31 | echo "Error. Missing parameters:" 32 | echo " Expected contained value" 33 | echo " (Optional) Logs from the test or returned message" 34 | return 1 35 | fi 36 | 37 | } 38 | 39 | # Check if the execution log of some command does not contain an expected pattern 40 | # $1: Expected contained value 41 | # $2: (Optional) Logs from the test or returned message 42 | logs_not_contains() { 43 | 44 | if [ "$#" -ge 1 ] 45 | then 46 | test_name=$(get_test_name_message) 47 | 48 | if [ "$#" -eq 2 ] 49 | then 50 | assertNotContains "$test_name should contain '$1'" "$2" "$1" 51 | return 0 52 | elif [ -e "${_shunit_test_}.log" ] 53 | then 54 | text_contained=0 55 | if [[ "$(cat ${_shunit_test_}.log)" == *"$1"* ]]; then 56 | text_contained=1 57 | fi 58 | 59 | assertEquals "$test_name should not contain '$1'" "0" "$text_contained" 60 | return 0 61 | else 62 | echo "Error. No log to inspect" 63 | return 1 64 | fi 65 | else 66 | echo "Error. Missing parameters:" 67 | echo " Expected contained value" 68 | echo " (Optional) Logs from the test or returned message" 69 | return 1 70 | fi 71 | 72 | } 73 | 74 | # Get proper message to display when referring to the execution 75 | get_test_name_message() { 76 | if [ -z "${_shunit_test_}" ] 77 | then 78 | test_name="Message from execution" 79 | else 80 | test_name="Message from execution of test '${_shunit_test_}'" 81 | fi 82 | 83 | echo "$test_name" 84 | } 85 | -------------------------------------------------------------------------------- /src/hooks/result.inc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Check the execution of some command is ok 5 | # $1: Returned code by process 6 | execution_success() { 7 | 8 | if [ "$#" -eq 1 ] 9 | then 10 | # shellcheck disable=SC2154 11 | if [ -z "${_shunit_test_}" ] 12 | then 13 | test_name="Execution" 14 | else 15 | test_name="Execution of test '${_shunit_test_}'" 16 | fi 17 | 18 | assertEquals "$test_name should retrieve exit code 0" "0" "$1" 19 | return 0 20 | else 21 | echo "Error. Missing parameters:" 22 | echo " Returned code by process" 23 | return 1 24 | fi 25 | 26 | } 27 | 28 | # Check a generic execution is ok 29 | # $1: Returned code by the process 30 | # $2: Expected excerpt 31 | # $3: (Optional) Execution log 32 | execution_should_success() { 33 | 34 | if [ "$#" -eq 3 ] 35 | then 36 | execution_success "$1" 37 | logs_contains "$2" "$3" 38 | elif [ "$#" -eq 2 ] 39 | then 40 | execution_success "$1" 41 | logs_contains "$2" 42 | else 43 | echo "Error. Missing parameters:" 44 | echo " Returned code by the process" 45 | echo " Expected excerpt" 46 | echo " (Optional) Execution log" 47 | return 1 48 | fi 49 | 50 | } 51 | 52 | # Check the execution of the Jenkinsfile should succed 53 | # $1: Returned code by the process 54 | # $2: (Optional) Execution log 55 | jenkinsfile_execution_should_succeed() { 56 | 57 | if [ "$#" -eq 2 ] 58 | then 59 | execution_success "$1" 60 | logs_contains "[Pipeline] End of Pipeline" "$2" 61 | logs_contains "Finished: SUCCESS" "$2" 62 | elif [ "$#" -eq 1 ] 63 | then 64 | execution_success "$1" 65 | logs_contains "[Pipeline] End of Pipeline" 66 | logs_contains "Finished: SUCCESS" 67 | else 68 | echo "Error. Missing parameters:" 69 | echo " Returned code by the process" 70 | echo " (Optional) Execution log" 71 | return 1 72 | fi 73 | 74 | } 75 | 76 | # Check the execution of the Jenkinsfile should fail 77 | # $1: Returned code by the process 78 | # $2: (Optional) Execution log 79 | jenkinsfile_execution_should_fail() { 80 | 81 | if [ "$#" -eq 2 ] 82 | then 83 | # The execution should be success while the execution of the pipeline should fail 84 | execution_success "$1" 85 | logs_contains "[Pipeline] End of Pipeline" "$2" 86 | logs_contains "Finished: FAILURE" "$2" 87 | elif [ "$#" -eq 1 ] 88 | then 89 | # The execution should be success while the execution of the pipeline should fail 90 | execution_success "$1" 91 | logs_contains "[Pipeline] End of Pipeline" 92 | logs_contains "Finished: FAILURE" 93 | else 94 | echo "Error. Missing parameters:" 95 | echo " Returned code by the process" 96 | echo " (Optional) Execution log" 97 | return 1 98 | fi 99 | 100 | } 101 | 102 | # Check the execution of the Jenkinsfile should be unstable 103 | # $1: Returned code by the process 104 | # $2: (Optional) Execution log 105 | jenkinsfile_execution_should_be_unstable() { 106 | 107 | if [ "$#" -eq 2 ] 108 | then 109 | # The execution should be success while the execution of the pipeline should be unstable 110 | execution_success "$1" 111 | logs_contains "[Pipeline] End of Pipeline" "$2" 112 | logs_contains "Finished: UNSTABLE" "$2" 113 | elif [ "$#" -eq 1 ] 114 | then 115 | # The execution should be success while the execution of the pipeline should be unstable 116 | execution_success "$1" 117 | logs_contains "[Pipeline] End of Pipeline" 118 | logs_contains "Finished: UNSTABLE" 119 | else 120 | echo "Error. Missing parameters:" 121 | echo " Returned code by the process" 122 | echo " (Optional) Execution log" 123 | return 1 124 | fi 125 | 126 | } 127 | 128 | # Check the generation of the Dockerfile should fail 129 | # $1: Returned code by the process 130 | # $2: Execution log 131 | docker_generation_should_fail() { 132 | 133 | if [ "$#" -eq 2 ] 134 | then 135 | # The execution should be success while the generation should have error messages in the log 136 | execution_success "$1" 137 | logs_contains "[ERROR]" "$2" 138 | else 139 | echo "Error. Missing parameters:" 140 | echo " Returned code by the process" 141 | echo " Execution log" 142 | return 1 143 | fi 144 | 145 | } 146 | -------------------------------------------------------------------------------- /src/hooks/workspace.inc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Return the workspace 5 | # $1: (Optional) Workspace directory. If not specified, 'WORKSPACE' env variable must be defined. 6 | # If the env variable is set, this parameter will override it 7 | read_workspace() { 8 | 9 | if [ "$#" -eq 1 ] 10 | then 11 | if [ -z "$1" ] 12 | then 13 | if [ -z "$WORKSPACE" ] 14 | then 15 | workspace_dir="" 16 | else 17 | workspace_dir="$WORKSPACE" 18 | fi 19 | else 20 | workspace_dir="$1" 21 | fi 22 | else 23 | if [ -z "$WORKSPACE" ] 24 | then 25 | workspace_dir="" 26 | else 27 | workspace_dir="$WORKSPACE" 28 | fi 29 | fi 30 | echo "$workspace_dir" 31 | 32 | } 33 | 34 | # Check if a directory exists 35 | # $1: (Optional) Workspace directory. If not specified, 'WORKSPACE' env variable must be defined. 36 | # If the env variable is set, this parameter will override it 37 | workspace_exists() { 38 | 39 | workspace_dir=$(read_workspace "$1") 40 | assertNotEquals "Workspace is not configured. Please set the WORKSPACE environment variable or pass it as parameter" "" "$workspace_dir" 41 | 42 | if [ -d "$workspace_dir" ] 43 | then 44 | valid_folder=1 45 | else 46 | valid_folder=0 47 | fi 48 | assertEquals "$workspace_dir is not a valid folder" "1" "$valid_folder" 49 | 50 | return 0 51 | 52 | } 53 | 54 | # Check if a directory does not exist 55 | # $1: (Optional) Workspace directory. If not specified, 'WORKSPACE' env variable must be defined. 56 | # If the env variable is set, this parameter will override it 57 | workspace_does_not_exist() { 58 | 59 | workspace_dir=$(read_workspace "$1") 60 | assertNotEquals "Workspace is not configured. Please set the WORKSPACE environment variable or pass it as parameter" "" "$workspace_dir" 61 | 62 | if [ -d "$workspace_dir" ] 63 | then 64 | valid_folder=1 65 | else 66 | valid_folder=0 67 | fi 68 | assertEquals "$workspace_dir should not be a valid folder" "0" "$valid_folder" 69 | 70 | return 0 71 | 72 | } 73 | 74 | # Check if a file exists in the workspace 75 | # $1: File to check the existence 76 | # $2: (Optional) Workspace directory. If not specified, 'WORKSPACE' env variable must be defined. 77 | # If the env variable is set, this parameter will override it 78 | file_exists_in_workspace() { 79 | 80 | if [ "$#" -ge 1 ] 81 | then 82 | workspace_dir=$(read_workspace "$2") 83 | workspace_exists "$workspace_dir" 84 | 85 | if [ -e "$workspace_dir/$1" ] 86 | then 87 | existing_file=1 88 | else 89 | existing_file=0 90 | fi 91 | assertEquals "Not found $workspace_dir/$1" "1" "$existing_file" 92 | 93 | return 0 94 | else 95 | echo "Error. Missing parameters:" 96 | echo " File to check the existence" 97 | echo " (Optional) Workspace directory. If not specified, 'WORKSPACE' env variable must be defined" 98 | return 1 99 | fi 100 | 101 | } 102 | 103 | # Check if a file does not exist in the workspace 104 | # $1: File to check the existence 105 | # $2: (Optional) Workspace directory. If not specified, 'WORKSPACE' env variable must be defined. 106 | # If the env variable is set, this parameter will override it 107 | file_does_not_exist_in_workspace() { 108 | 109 | if [ "$#" -ge 1 ] 110 | then 111 | workspace_dir=$(read_workspace "$2") 112 | workspace_exists "$workspace_dir" 113 | 114 | if [ -e "$workspace_dir/$1" ] 115 | then 116 | existing_file=1 117 | else 118 | existing_file=0 119 | fi 120 | assertEquals "Found $workspace_dir/$1" "0" "$existing_file" 121 | 122 | return 0 123 | else 124 | echo "Error. Missing parameters:" 125 | echo " File to check the existence" 126 | echo " (Optional) Workspace directory. If not specified, 'WORKSPACE' env variable must be defined" 127 | return 1 128 | fi 129 | 130 | } 131 | 132 | # Check if a file contains a text 133 | # $1: Text to check 134 | # $2: File to check 135 | # $3: (Optional) Workspace directory. If not specified, 'WORKSPACE' env variable must be defined. 136 | # If the env variable is set, this parameter will override it 137 | file_contains_text() { 138 | 139 | if [ "$#" -ge 2 ] 140 | then 141 | workspace_dir=$(read_workspace "$3") 142 | workspace_exists "$workspace_dir" 143 | 144 | file_exists_in_workspace "$2" "$workspace_dir" 145 | 146 | if grep -q "$1" "$workspace_dir/$2" 147 | then 148 | contains_text=1 149 | else 150 | contains_text=0 151 | fi 152 | assertEquals "Expected text '$1' not found in $2" "1" "$contains_text" 153 | 154 | return 0 155 | else 156 | echo "Error. Missing parameters:" 157 | echo " Text to check" 158 | echo " File to check" 159 | echo " (Optional) Workspace directory. If not specified, 'WORKSPACE' env variable must be defined" 160 | return 1 161 | fi 162 | 163 | } 164 | 165 | # Check if a file does not contains a text 166 | # $1: Text to check 167 | # $2: File to check 168 | # $3: (Optional) Workspace directory. If not specified, 'WORKSPACE' env variable must be defined. 169 | # If the env variable is set, this parameter will override it 170 | file_does_not_contains_text() { 171 | 172 | if [ "$#" -ge 2 ] 173 | then 174 | workspace_dir=$(read_workspace "$3") 175 | workspace_exists "$workspace_dir" 176 | 177 | file_exists_in_workspace "$2" "$workspace_dir" 178 | 179 | if grep -q "$1" "$workspace_dir/$2" 180 | then 181 | contains_text=1 182 | else 183 | contains_text=0 184 | fi 185 | assertEquals "Unexpected text '$1' found in $2" "0" "$contains_text" 186 | 187 | return 0 188 | else 189 | echo "Error. Missing parameters:" 190 | echo " Text to check" 191 | echo " File to check" 192 | echo " (Optional) Workspace directory. If not specified, 'WORKSPACE' env variable must be defined" 193 | return 1 194 | fi 195 | 196 | } 197 | -------------------------------------------------------------------------------- /src/jfr/jenkinsfile-runner.inc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # function to run a docker image 5 | # $1: tag of the docker image 6 | # $2: Path to Jenkinsfile 7 | run_jfr_docker_image() { 8 | if [ "$#" -eq 2 ] 9 | then 10 | run_jfr_docker_image_with_docker_and_jfr_options "$1" "$2" "" "" 11 | return 0 12 | else 13 | echo "Error. Missing parameters:" 14 | echo " Tag for the docker image to run" 15 | echo " Path to Jenkinsfile" 16 | fi 17 | } 18 | 19 | # function to run a docker image with additional docker options 20 | # $1: tag of the docker image 21 | # $2: Path to Jenkinsfile 22 | # $3: Docker options 23 | run_jfr_docker_image_with_docker_options() { 24 | if [ "$#" -eq 3 ] 25 | then 26 | run_jfr_docker_image_with_docker_and_jfr_options "$1" "$2" "$3" "" 27 | return 0 28 | else 29 | echo "Error. Missing parameters:" 30 | echo " Tag for the docker image to run" 31 | echo " Path to Jenkinsfile" 32 | echo " Docker Options" 33 | fi 34 | } 35 | 36 | 37 | # function to run a docker image with additional options passed to Jenkinsfile-runner 38 | # $1: tag of the docker image 39 | # $2: Path to Jenkinsfile 40 | # $3: Jenksinfile-runner options 41 | run_jfr_docker_image_with_jfr_options() { 42 | if [ "$#" -eq 3 ] 43 | then 44 | run_jfr_docker_image_with_docker_and_jfr_options "$1" "$2" "" "$3" 45 | return 0 46 | else 47 | echo "Error. Missing parameters:" 48 | echo " Tag for the docker image to run" 49 | echo " Path to Jenkinsfile" 50 | echo " Jenksinfile-runner Options" 51 | fi 52 | } 53 | 54 | 55 | # function to run a docker image with both additional docker options and options for Jenkinsfile-runner 56 | # $1: tag of the docker image 57 | # $2: Path to Jenkinsfile 58 | # $3: Docker options 59 | # $4: Jenksinfile-runner options 60 | run_jfr_docker_image_with_docker_and_jfr_options() { 61 | if [ "$#" -eq 4 ] 62 | then 63 | if [ -z "$JAVA_OPTS" ] 64 | then 65 | if [ ! -z "${_shunit_test_}" ] 66 | then 67 | docker run --rm $3 -v "$2":/workspace/Jenkinsfile "$1" $4 2>&1 | tee "${_shunit_test_}.log" 68 | else 69 | docker run --rm $3 -v "$2":/workspace/Jenkinsfile "$1" $4 70 | fi 71 | else 72 | if [ ! -z "${_shunit_test_}" ] 73 | then 74 | docker run -e JAVA_OPTS="$JAVA_OPTS" --rm $3 -v "$2":/workspace/Jenkinsfile "$1" $4 2>&1 | tee "${_shunit_test_}.log" 75 | else 76 | docker run -e JAVA_OPTS="$JAVA_OPTS" --rm $3 -v "$2":/workspace/Jenkinsfile "$1" $4 77 | fi 78 | fi 79 | else 80 | echo "Error. Missing parameters:" 81 | echo " Tag for the docker image to run" 82 | echo " Path to Jenkinsfile" 83 | echo " Docker Options" 84 | echo " Jenksinfile-runner Options" 85 | fi 86 | } 87 | 88 | -------------------------------------------------------------------------------- /src/utilities/timeout.inc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # 5 minutes by default 5 | default_timeout=300 6 | export TIMEOUT=$default_timeout 7 | 8 | # 9 | create_test_file() { 10 | 11 | if [ "$#" -eq 1 ] 12 | then 13 | rm -f "$1" 14 | echo "#!/bin/bash" >> "$1" 15 | return 0 16 | else 17 | echo "Error. Missing the parameter for the test file to create." 18 | return 1 19 | fi 20 | } 21 | 22 | # Set the timeout. 23 | # $1: timeout in seconds. It must be a number greater than 0. Set 0 to disable the timeout and -1 to reset to default value 24 | set_timeout() { 25 | 26 | if [ "$#" -eq 1 ] 27 | then 28 | if [ "$1" -gt 0 ] 29 | then 30 | export TIMEOUT=$1 31 | return 0 32 | elif [ "$1" -eq 0 ] 33 | then 34 | unset TIMEOUT 35 | return 0 36 | elif [ "$1" -eq -1 ] 37 | then 38 | export TIMEOUT=$default_timeout 39 | return 0 40 | else 41 | echo "[ERROR] Wrong timeout value. The timeout value is a number of seconds greater than 0. Use '0' to disable the timeout and '-1' to reset to default value" 42 | return 1 43 | fi 44 | else 45 | echo "Error. Wrong number of parameters. Use timeout timeout_value" 46 | echo " The timeout value is a number of seconds greater than 0. Use '0' to disable the timeout and '-1' to reset to default value" 47 | return 1 48 | fi 49 | 50 | } 51 | 52 | # Generate a test that is executed with or without timeout based on the original test 53 | # $1: Name of the original test 54 | # $2: File where create the test (full path) 55 | create_test_with_template() { 56 | 57 | if [ "$#" -eq 2 ] 58 | then 59 | test_name="$1_with_timeout" 60 | { 61 | echo ""; 62 | echo "$test_name() {"; 63 | echo " if [ -z \"\$TIMEOUT\" ]"; 64 | echo " then"; 65 | echo " $1"; 66 | echo " else"; 67 | echo " run_with_timeout $1" 68 | echo " fi" 69 | echo "}" 70 | echo "" 71 | } >> "$2" 72 | echo "$test_name" 73 | else 74 | echo "Error. Missing parameters:" 75 | echo " Name of the original test" 76 | echo " File where create the test (full path)" 77 | return 1 78 | fi 79 | 80 | } 81 | 82 | # Execute a function setting a timeout. If the timeout happens then the execution of the function is killed and a message is displayed 83 | # $1: name of the function to execute 84 | run_with_timeout() { 85 | 86 | cmd="$1" 87 | timeout="$TIMEOUT" 88 | 89 | ( 90 | eval "$cmd" & 91 | child=$! 92 | trap -- "" SIGTERM 93 | ( 94 | sleep $timeout 95 | # Only kills and displays message if the function is still running 96 | # shellcheck disable=SC2009 97 | if [ "$(ps -p $child | grep -cv PID )" -ne 0 ] 98 | then 99 | echo "[ERROR] $1 timeout. Passed $timeout seconds" 100 | kill_process_and_subprocess $child 101 | fi 102 | ) & 103 | wait $child 104 | ) 105 | 106 | } 107 | 108 | # Kill the process and all the subprocesses that it can open 109 | # $1: PID of the process to kill 110 | kill_process_and_subprocess() { 111 | 112 | for subprocess in $(pgrep -P "$1") 113 | do 114 | # Kill the subprocess 115 | kill_process_and_subprocess "$subprocess" 116 | done 117 | # Kill execution 118 | timeout 30 kill "$1" 2> /dev/null 119 | 120 | } 121 | -------------------------------------------------------------------------------- /src/utilities/utils.inc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # file with miscellaneous utils 5 | 6 | # $1: origin 7 | # $2: string to remove from origin 8 | remove_string() { 9 | 10 | if [ "$#" -gt 1 ] 11 | then 12 | origin="$1" 13 | origin_length=${#origin} 14 | 15 | to_remove="$2" 16 | length_to_remove=${#to_remove} 17 | 18 | result=$(echo "$origin" | cut -b "$length_to_remove"-"$origin_length") 19 | 20 | echo "$result" 21 | return 0 22 | else 23 | echo "Error. Missing parameters. Use remove_string origin string_to_remove" 24 | return 1 25 | fi 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for test the framework 2 | .PHONY: test 3 | 4 | test: 5 | rm -rf ../.shunit2 6 | rm -rf .testing 7 | mkdir -p .testing 8 | # TODO So far, the released tags do not contains all the macros and functions that 9 | # master branch does (assertContains, e.g.). Once a new version containing all 10 | # the functionalyty is released we should clone using --branch 11 | git clone https://github.com/kward/shunit2 ../.shunit2 && cd ../.shunit2 && git checkout abb3ab2fef8c549933e378ae3d12127dfc748e73 12 | ./workspace_hook_tests.sh 13 | ./tests.sh 14 | ./timeout-tests.sh 15 | -------------------------------------------------------------------------------- /tests/test_resources/test_all_hooks/Jenkinsfile: -------------------------------------------------------------------------------- 1 | stage('Echo message') { 2 | node { 3 | String message = "This is the message to find in the logs" 4 | 5 | echo message 6 | writeFile file: 'message.txt', text: message 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/test_resources/test_all_hooks/packager-config.yml: -------------------------------------------------------------------------------- 1 | bundle: 2 | groupId: "io.jenkins.tools.custom-war-packager.demo" 3 | artifactId: "jenkinsfile-runner" 4 | vendor: "Jenkins project" 5 | title: "Jenkinsfile Runner demo" 6 | description: "Jenkinsfile Runner Docker Image, produced by Custom WAR Packager" 7 | buildSettings: 8 | jenkinsfileRunner: 9 | source: 10 | groupId: "io.jenkins" 11 | artifactId: "jenkinsfile-runner" 12 | build: 13 | noCache: true 14 | source: 15 | git: https://github.com/jenkinsci/jenkinsfile-runner.git 16 | branch: 1.0-beta-6 17 | docker: 18 | base: "jenkins/jenkins:2.138.2" 19 | tag: "jenkins-experimental/jenkinsfile-runner-demo" 20 | build: false 21 | war: 22 | groupId: "org.jenkins-ci.main" 23 | artifactId: "jenkins-war" 24 | source: 25 | version: "2.138.2" 26 | plugins: 27 | - groupId: "org.jenkins-ci.plugins.workflow" 28 | artifactId: "workflow-job" 29 | source: 30 | version: "2.24" 31 | - groupId: "org.jenkins-ci.plugins.workflow" 32 | artifactId: "workflow-cps" 33 | source: 34 | version: "2.48" 35 | - groupId: "org.jenkins-ci.plugins.workflow" 36 | artifactId: "workflow-api" 37 | source: 38 | version: "2.27" 39 | - groupId: "org.jenkins-ci.plugins.workflow" 40 | artifactId: "workflow-step-api" 41 | source: 42 | version: "2.14" 43 | - groupId: "org.jenkins-ci.plugins" 44 | artifactId: "pipeline-utility-steps" 45 | source: 46 | version: "2.1.0" 47 | - groupId: "org.jenkins-ci.plugins" 48 | artifactId: "cloudbees-folder" 49 | source: 50 | version: "6.4" 51 | - groupId: "org.jenkins-ci.plugins" 52 | artifactId: "credentials" 53 | source: 54 | version: "2.1.11" 55 | - groupId: "org.jenkins-ci.plugins" 56 | artifactId: "structs" 57 | source: 58 | version: "1.14" 59 | - groupId: "org.jenkins-ci.plugins" 60 | artifactId: "scm-api" 61 | source: 62 | version: "2.2.6" 63 | - groupId: "org.jenkins-ci.plugins" 64 | artifactId: "ssh-credentials" 65 | source: 66 | version: "1.12" 67 | - groupId: "org.jenkins-ci.plugins" 68 | artifactId: "credentials-binding" 69 | source: 70 | version: "1.16" 71 | - groupId: "org.jenkins-ci.plugins.workflow" 72 | artifactId: "workflow-aggregator" 73 | source: 74 | version: "2.5" 75 | - groupId: "io.jenkins" 76 | artifactId: "configuration-as-code" 77 | source: 78 | version: "1.1" 79 | systemProperties: { 80 | jenkins.model.Jenkins.slaveAgentPort: "50000", 81 | jenkins.model.Jenkins.slaveAgentPortEnforce: "true"} -------------------------------------------------------------------------------- /tests/test_resources/test_failing_docker_image/packager-config.yml: -------------------------------------------------------------------------------- 1 | bundle: 2 | groupId: "io.jenkins.tools.custom-war-packager.demo" 3 | artifactId: "jenkinsfile-runner" 4 | vendor: "Jenkins project" 5 | title: "Jenkinsfile Runner demo" 6 | description: "Jenkinsfile Runner Docker Image, produced by Custom WAR Packager" 7 | buildSettings: 8 | jenkinsfileRunner: 9 | source: 10 | groupId: "io.jenkins" 11 | artifactId: "jenkinsfile-runner" 12 | build: 13 | noCache: true 14 | source: 15 | git: https://github.com/jenkinsci/jenkinsfile-runner.git 16 | branch: fake-version 17 | docker: 18 | base: "jenkins/jenkins:2.138.2" 19 | tag: "jenkins-experimental/jenkinsfile-runner-demo" 20 | build: false 21 | war: 22 | groupId: "org.jenkins-ci.main" 23 | artifactId: "jenkins-war" 24 | source: 25 | version: "2.138.2" 26 | plugins: 27 | - groupId: "org.jenkins-ci.plugins.workflow" 28 | artifactId: "workflow-job" 29 | source: 30 | version: "2.24" 31 | - groupId: "org.jenkins-ci.plugins.workflow" 32 | artifactId: "workflow-cps" 33 | source: 34 | version: "2.48" 35 | - groupId: "org.jenkins-ci.plugins.workflow" 36 | artifactId: "workflow-api" 37 | source: 38 | version: "2.27" 39 | - groupId: "org.jenkins-ci.plugins.workflow" 40 | artifactId: "workflow-step-api" 41 | source: 42 | version: "2.14" 43 | - groupId: "org.jenkins-ci.plugins" 44 | artifactId: "pipeline-utility-steps" 45 | source: 46 | version: "2.1.0" 47 | - groupId: "org.jenkins-ci.plugins" 48 | artifactId: "cloudbees-folder" 49 | source: 50 | version: "6.4" 51 | - groupId: "org.jenkins-ci.plugins" 52 | artifactId: "credentials" 53 | source: 54 | version: "2.1.11" 55 | - groupId: "org.jenkins-ci.plugins" 56 | artifactId: "structs" 57 | source: 58 | version: "1.14" 59 | - groupId: "org.jenkins-ci.plugins" 60 | artifactId: "scm-api" 61 | source: 62 | version: "2.2.6" 63 | - groupId: "org.jenkins-ci.plugins" 64 | artifactId: "ssh-credentials" 65 | source: 66 | version: "1.12" 67 | - groupId: "org.jenkins-ci.plugins" 68 | artifactId: "credentials-binding" 69 | source: 70 | version: "1.16" 71 | - groupId: "org.jenkins-ci.plugins.workflow" 72 | artifactId: "workflow-aggregator" 73 | source: 74 | version: "2.5" 75 | - groupId: "io.jenkins" 76 | artifactId: "configuration-as-code" 77 | source: 78 | version: "1.1" 79 | systemProperties: { 80 | jenkins.model.Jenkins.slaveAgentPort: "50000", 81 | jenkins.model.Jenkins.slaveAgentPortEnforce: "true"} 82 | -------------------------------------------------------------------------------- /tests/test_resources/test_jenkinsfile_fail/Jenkinsfile: -------------------------------------------------------------------------------- 1 | node { 2 | currentBuild.result = 'FAILED' 3 | } 4 | -------------------------------------------------------------------------------- /tests/test_resources/test_jenkinsfile_fail/packager-config.yml: -------------------------------------------------------------------------------- 1 | bundle: 2 | groupId: "io.jenkins.tools.custom-war-packager.demo" 3 | artifactId: "jenkinsfile-runner" 4 | vendor: "Jenkins project" 5 | title: "Jenkinsfile Runner demo" 6 | description: "Jenkinsfile Runner Docker Image, produced by Custom WAR Packager" 7 | buildSettings: 8 | jenkinsfileRunner: 9 | source: 10 | groupId: "io.jenkins" 11 | artifactId: "jenkinsfile-runner" 12 | build: 13 | noCache: true 14 | source: 15 | git: https://github.com/jenkinsci/jenkinsfile-runner.git 16 | branch: parent-1.0-beta-4 17 | docker: 18 | base: "jenkins/jenkins:2.138.2" 19 | tag: "jenkins-experimental/jenkinsfile-runner-demo" 20 | build: false 21 | war: 22 | groupId: "org.jenkins-ci.main" 23 | artifactId: "jenkins-war" 24 | source: 25 | version: "2.138.2" 26 | plugins: 27 | - groupId: "org.jenkins-ci.plugins.workflow" 28 | artifactId: "workflow-job" 29 | source: 30 | version: "2.24" 31 | - groupId: "org.jenkins-ci.plugins.workflow" 32 | artifactId: "workflow-cps" 33 | source: 34 | version: "2.48" 35 | - groupId: "org.jenkins-ci.plugins.workflow" 36 | artifactId: "workflow-api" 37 | source: 38 | version: "2.27" 39 | - groupId: "org.jenkins-ci.plugins.workflow" 40 | artifactId: "workflow-step-api" 41 | source: 42 | version: "2.14" 43 | - groupId: "org.jenkins-ci.plugins" 44 | artifactId: "pipeline-utility-steps" 45 | source: 46 | version: "2.1.0" 47 | - groupId: "org.jenkins-ci.plugins" 48 | artifactId: "cloudbees-folder" 49 | source: 50 | version: "6.4" 51 | - groupId: "org.jenkins-ci.plugins" 52 | artifactId: "credentials" 53 | source: 54 | version: "2.1.11" 55 | - groupId: "org.jenkins-ci.plugins" 56 | artifactId: "structs" 57 | source: 58 | version: "1.14" 59 | - groupId: "org.jenkins-ci.plugins" 60 | artifactId: "scm-api" 61 | source: 62 | version: "2.2.6" 63 | - groupId: "org.jenkins-ci.plugins" 64 | artifactId: "ssh-credentials" 65 | source: 66 | version: "1.12" 67 | - groupId: "org.jenkins-ci.plugins" 68 | artifactId: "credentials-binding" 69 | source: 70 | version: "1.16" 71 | - groupId: "org.jenkins-ci.plugins.workflow" 72 | artifactId: "workflow-aggregator" 73 | source: 74 | version: "2.5" 75 | - groupId: "io.jenkins" 76 | artifactId: "configuration-as-code" 77 | source: 78 | version: "1.1" 79 | systemProperties: { 80 | jenkins.model.Jenkins.slaveAgentPort: "50000", 81 | jenkins.model.Jenkins.slaveAgentPortEnforce: "true"} 82 | -------------------------------------------------------------------------------- /tests/test_resources/test_jenkinsfile_unstable/Jenkinsfile: -------------------------------------------------------------------------------- 1 | node { 2 | currentBuild.result = 'UNSTABLE' 3 | } 4 | -------------------------------------------------------------------------------- /tests/test_resources/test_jenkinsfile_unstable/packager-config.yml: -------------------------------------------------------------------------------- 1 | bundle: 2 | groupId: "io.jenkins.tools.custom-war-packager.demo" 3 | artifactId: "jenkinsfile-runner" 4 | vendor: "Jenkins project" 5 | title: "Jenkinsfile Runner demo" 6 | description: "Jenkinsfile Runner Docker Image, produced by Custom WAR Packager" 7 | buildSettings: 8 | jenkinsfileRunner: 9 | source: 10 | groupId: "io.jenkins" 11 | artifactId: "jenkinsfile-runner" 12 | build: 13 | noCache: true 14 | source: 15 | git: https://github.com/jenkinsci/jenkinsfile-runner.git 16 | branch: parent-1.0-beta-4 17 | docker: 18 | base: "jenkins/jenkins:2.138.2" 19 | tag: "jenkins-experimental/jenkinsfile-runner-demo" 20 | build: false 21 | war: 22 | groupId: "org.jenkins-ci.main" 23 | artifactId: "jenkins-war" 24 | source: 25 | version: "2.138.2" 26 | plugins: 27 | - groupId: "org.jenkins-ci.plugins.workflow" 28 | artifactId: "workflow-job" 29 | source: 30 | version: "2.24" 31 | - groupId: "org.jenkins-ci.plugins.workflow" 32 | artifactId: "workflow-cps" 33 | source: 34 | version: "2.48" 35 | - groupId: "org.jenkins-ci.plugins.workflow" 36 | artifactId: "workflow-api" 37 | source: 38 | version: "2.27" 39 | - groupId: "org.jenkins-ci.plugins.workflow" 40 | artifactId: "workflow-step-api" 41 | source: 42 | version: "2.14" 43 | - groupId: "org.jenkins-ci.plugins" 44 | artifactId: "pipeline-utility-steps" 45 | source: 46 | version: "2.1.0" 47 | - groupId: "org.jenkins-ci.plugins" 48 | artifactId: "cloudbees-folder" 49 | source: 50 | version: "6.4" 51 | - groupId: "org.jenkins-ci.plugins" 52 | artifactId: "credentials" 53 | source: 54 | version: "2.1.11" 55 | - groupId: "org.jenkins-ci.plugins" 56 | artifactId: "structs" 57 | source: 58 | version: "1.14" 59 | - groupId: "org.jenkins-ci.plugins" 60 | artifactId: "scm-api" 61 | source: 62 | version: "2.2.6" 63 | - groupId: "org.jenkins-ci.plugins" 64 | artifactId: "ssh-credentials" 65 | source: 66 | version: "1.12" 67 | - groupId: "org.jenkins-ci.plugins" 68 | artifactId: "credentials-binding" 69 | source: 70 | version: "1.16" 71 | - groupId: "org.jenkins-ci.plugins.workflow" 72 | artifactId: "workflow-aggregator" 73 | source: 74 | version: "2.5" 75 | - groupId: "io.jenkins" 76 | artifactId: "configuration-as-code" 77 | source: 78 | version: "1.1" 79 | systemProperties: { 80 | jenkins.model.Jenkins.slaveAgentPort: "50000", 81 | jenkins.model.Jenkins.slaveAgentPortEnforce: "true"} 82 | -------------------------------------------------------------------------------- /tests/test_resources/test_timeout/Jenkinsfile: -------------------------------------------------------------------------------- 1 | stage('Read Evergreen YAML') { 2 | node { 3 | while(true) { 4 | // it hangs 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/test_resources/test_with_default_tag/packager-config.yml: -------------------------------------------------------------------------------- 1 | bundle: 2 | groupId: "io.jenkins.tools.custom-war-packager.demo" 3 | artifactId: "jenkinsfile-runner" 4 | vendor: "Jenkins project" 5 | title: "Jenkinsfile Runner demo" 6 | description: "Jenkinsfile Runner Docker Image, produced by Custom WAR Packager" 7 | buildSettings: 8 | jenkinsfileRunner: 9 | source: 10 | groupId: "io.jenkins" 11 | artifactId: "jenkinsfile-runner" 12 | build: 13 | noCache: true 14 | source: 15 | git: https://github.com/jenkinsci/jenkinsfile-runner.git 16 | branch: parent-1.0-beta-4 17 | docker: 18 | base: "jenkins/jenkins:2.138.2" 19 | tag: "jenkins-experimental/jenkinsfile-runner-demo" 20 | build: false 21 | war: 22 | groupId: "org.jenkins-ci.main" 23 | artifactId: "jenkins-war" 24 | source: 25 | version: "2.138.2" 26 | plugins: 27 | - groupId: "org.jenkins-ci.plugins.workflow" 28 | artifactId: "workflow-job" 29 | source: 30 | version: "2.24" 31 | - groupId: "org.jenkins-ci.plugins.workflow" 32 | artifactId: "workflow-cps" 33 | source: 34 | version: "2.48" 35 | - groupId: "org.jenkins-ci.plugins.workflow" 36 | artifactId: "workflow-api" 37 | source: 38 | version: "2.27" 39 | - groupId: "org.jenkins-ci.plugins.workflow" 40 | artifactId: "workflow-step-api" 41 | source: 42 | version: "2.14" 43 | - groupId: "org.jenkins-ci.plugins" 44 | artifactId: "pipeline-utility-steps" 45 | source: 46 | version: "2.1.0" 47 | - groupId: "org.jenkins-ci.plugins" 48 | artifactId: "cloudbees-folder" 49 | source: 50 | version: "6.4" 51 | - groupId: "org.jenkins-ci.plugins" 52 | artifactId: "credentials" 53 | source: 54 | version: "2.1.11" 55 | - groupId: "org.jenkins-ci.plugins" 56 | artifactId: "structs" 57 | source: 58 | version: "1.14" 59 | - groupId: "org.jenkins-ci.plugins" 60 | artifactId: "scm-api" 61 | source: 62 | version: "2.2.6" 63 | - groupId: "org.jenkins-ci.plugins" 64 | artifactId: "ssh-credentials" 65 | source: 66 | version: "1.12" 67 | - groupId: "org.jenkins-ci.plugins" 68 | artifactId: "credentials-binding" 69 | source: 70 | version: "1.16" 71 | - groupId: "org.jenkins-ci.plugins.workflow" 72 | artifactId: "workflow-aggregator" 73 | source: 74 | version: "2.5" 75 | - groupId: "io.jenkins" 76 | artifactId: "configuration-as-code" 77 | source: 78 | version: "1.1" 79 | systemProperties: { 80 | jenkins.model.Jenkins.slaveAgentPort: "50000", 81 | jenkins.model.Jenkins.slaveAgentPortEnforce: "true"} 82 | -------------------------------------------------------------------------------- /tests/test_resources/test_with_default_tag_using_cwp_docker_image/packager-config.yml: -------------------------------------------------------------------------------- 1 | bundle: 2 | groupId: "io.jenkins.tools.custom-war-packager.demo" 3 | artifactId: "jenkinsfile-runner" 4 | vendor: "Jenkins project" 5 | title: "Jenkinsfile Runner demo" 6 | description: "Jenkinsfile Runner Docker Image, produced by Custom WAR Packager" 7 | buildSettings: 8 | jenkinsfileRunner: 9 | source: 10 | groupId: "io.jenkins" 11 | artifactId: "jenkinsfile-runner" 12 | build: 13 | noCache: true 14 | source: 15 | git: https://github.com/jenkinsci/jenkinsfile-runner.git 16 | branch: parent-1.0-beta-4 17 | docker: 18 | base: "jenkins/jenkins:2.138.2" 19 | tag: "jenkins-experimental/jenkinsfile-runner-demo" 20 | build: false 21 | war: 22 | groupId: "org.jenkins-ci.main" 23 | artifactId: "jenkins-war" 24 | source: 25 | version: "2.138.2" 26 | plugins: 27 | - groupId: "org.jenkins-ci.plugins.workflow" 28 | artifactId: "workflow-job" 29 | source: 30 | version: "2.24" 31 | - groupId: "org.jenkins-ci.plugins.workflow" 32 | artifactId: "workflow-cps" 33 | source: 34 | version: "2.48" 35 | - groupId: "org.jenkins-ci.plugins.workflow" 36 | artifactId: "workflow-api" 37 | source: 38 | version: "2.27" 39 | - groupId: "org.jenkins-ci.plugins.workflow" 40 | artifactId: "workflow-step-api" 41 | source: 42 | version: "2.14" 43 | - groupId: "org.jenkins-ci.plugins" 44 | artifactId: "pipeline-utility-steps" 45 | source: 46 | version: "2.1.0" 47 | - groupId: "org.jenkins-ci.plugins" 48 | artifactId: "cloudbees-folder" 49 | source: 50 | version: "6.4" 51 | - groupId: "org.jenkins-ci.plugins" 52 | artifactId: "credentials" 53 | source: 54 | version: "2.1.11" 55 | - groupId: "org.jenkins-ci.plugins" 56 | artifactId: "structs" 57 | source: 58 | version: "1.14" 59 | - groupId: "org.jenkins-ci.plugins" 60 | artifactId: "scm-api" 61 | source: 62 | version: "2.2.6" 63 | - groupId: "org.jenkins-ci.plugins" 64 | artifactId: "ssh-credentials" 65 | source: 66 | version: "1.12" 67 | - groupId: "org.jenkins-ci.plugins" 68 | artifactId: "credentials-binding" 69 | source: 70 | version: "1.16" 71 | - groupId: "org.jenkins-ci.plugins.workflow" 72 | artifactId: "workflow-aggregator" 73 | source: 74 | version: "2.5" 75 | - groupId: "io.jenkins" 76 | artifactId: "configuration-as-code" 77 | source: 78 | version: "1.1" 79 | systemProperties: { 80 | jenkins.model.Jenkins.slaveAgentPort: "50000", 81 | jenkins.model.Jenkins.slaveAgentPortEnforce: "true"} 82 | -------------------------------------------------------------------------------- /tests/test_resources/test_with_jfr_options/Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent any 3 | parameters { 4 | string(name: 'param1', defaultValue: '', description: 'Greeting message') 5 | } 6 | stages { 7 | stage('Build') { 8 | steps { 9 | echo 'Hello world!' 10 | echo "Value for param1: ${params.param1}" 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/test_resources/test_with_jfr_options/packager-config.yml: -------------------------------------------------------------------------------- 1 | bundle: 2 | groupId: "io.jenkins.tools.custom-war-packager.demo" 3 | artifactId: "jenkinsfile-runner" 4 | vendor: "Jenkins project" 5 | title: "Jenkinsfile Runner demo" 6 | description: "Jenkinsfile Runner Docker Image, produced by Custom WAR Packager" 7 | buildSettings: 8 | jenkinsfileRunner: 9 | source: 10 | groupId: "io.jenkins" 11 | artifactId: "jenkinsfile-runner" 12 | build: 13 | noCache: true 14 | source: 15 | git: https://github.com/jenkinsci/jenkinsfile-runner.git 16 | commit: 0a67d41049c882f5dd834b736210d943d5412cbb 17 | docker: 18 | base: "jenkins/jenkins:2.138.2" 19 | tag: "jenkins-experimental/jenkinsfile-runner-demo" 20 | build: false 21 | war: 22 | groupId: "org.jenkins-ci.main" 23 | artifactId: "jenkins-war" 24 | source: 25 | version: "2.138.2" 26 | plugins: 27 | - groupId: "org.jenkins-ci.plugins.workflow" 28 | artifactId: "workflow-job" 29 | source: 30 | version: "2.24" 31 | - groupId: "org.jenkins-ci.plugins.workflow" 32 | artifactId: "workflow-cps" 33 | source: 34 | version: "2.48" 35 | - groupId: "org.jenkins-ci.plugins.workflow" 36 | artifactId: "workflow-api" 37 | source: 38 | version: "2.27" 39 | - groupId: "org.jenkins-ci.plugins.workflow" 40 | artifactId: "workflow-step-api" 41 | source: 42 | version: "2.14" 43 | - groupId: "org.jenkins-ci.plugins" 44 | artifactId: "pipeline-utility-steps" 45 | source: 46 | version: "2.1.0" 47 | - groupId: "org.jenkins-ci.plugins" 48 | artifactId: "cloudbees-folder" 49 | source: 50 | version: "6.4" 51 | - groupId: "org.jenkins-ci.plugins" 52 | artifactId: "credentials" 53 | source: 54 | version: "2.1.11" 55 | - groupId: "org.jenkins-ci.plugins" 56 | artifactId: "structs" 57 | source: 58 | version: "1.14" 59 | - groupId: "org.jenkins-ci.plugins" 60 | artifactId: "scm-api" 61 | source: 62 | version: "2.2.6" 63 | - groupId: "org.jenkins-ci.plugins" 64 | artifactId: "ssh-credentials" 65 | source: 66 | version: "1.12" 67 | - groupId: "org.jenkins-ci.plugins" 68 | artifactId: "credentials-binding" 69 | source: 70 | version: "1.16" 71 | - groupId: "org.jenkins-ci.plugins.workflow" 72 | artifactId: "workflow-aggregator" 73 | source: 74 | version: "2.5" 75 | - groupId: "io.jenkins" 76 | artifactId: "configuration-as-code" 77 | source: 78 | version: "1.1" 79 | systemProperties: { 80 | jenkins.model.Jenkins.slaveAgentPort: "50000", 81 | jenkins.model.Jenkins.slaveAgentPortEnforce: "true"} 82 | -------------------------------------------------------------------------------- /tests/test_resources/test_with_tag/Jenkinsfile: -------------------------------------------------------------------------------- 1 | 2 | stage('Read Evergreen YAML') { 3 | node { 4 | // Discover core version using Pipeline utility steps 5 | sh 'wget https://raw.githubusercontent.com/jenkins-infra/evergreen/master/services/essentials.yaml' 6 | def essentialsYaml = readYaml(file: "essentials.yaml") 7 | echo "Jenkins Evergreen uses the following Core version: ${essentialsYaml.spec.core.version}" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/test_resources/test_with_tag/packager-config.yml: -------------------------------------------------------------------------------- 1 | bundle: 2 | groupId: "io.jenkins.tools.custom-war-packager.demo" 3 | artifactId: "jenkinsfile-runner" 4 | vendor: "Jenkins project" 5 | title: "Jenkinsfile Runner demo" 6 | description: "Jenkinsfile Runner Docker Image, produced by Custom WAR Packager" 7 | buildSettings: 8 | jenkinsfileRunner: 9 | source: 10 | groupId: "io.jenkins" 11 | artifactId: "jenkinsfile-runner" 12 | build: 13 | noCache: true 14 | source: 15 | git: https://github.com/jenkinsci/jenkinsfile-runner.git 16 | branch: parent-1.0-beta-4 17 | docker: 18 | base: "jenkins/jenkins:2.138.2" 19 | tag: "jenkins-experimental/jenkinsfile-runner-demo" 20 | build: false 21 | war: 22 | groupId: "org.jenkins-ci.main" 23 | artifactId: "jenkins-war" 24 | source: 25 | version: "2.138.2" 26 | plugins: 27 | - groupId: "org.jenkins-ci.plugins.workflow" 28 | artifactId: "workflow-job" 29 | source: 30 | version: "2.24" 31 | - groupId: "org.jenkins-ci.plugins.workflow" 32 | artifactId: "workflow-cps" 33 | source: 34 | version: "2.48" 35 | - groupId: "org.jenkins-ci.plugins.workflow" 36 | artifactId: "workflow-api" 37 | source: 38 | version: "2.27" 39 | - groupId: "org.jenkins-ci.plugins.workflow" 40 | artifactId: "workflow-step-api" 41 | source: 42 | version: "2.14" 43 | - groupId: "org.jenkins-ci.plugins" 44 | artifactId: "pipeline-utility-steps" 45 | source: 46 | version: "2.1.0" 47 | - groupId: "org.jenkins-ci.plugins" 48 | artifactId: "cloudbees-folder" 49 | source: 50 | version: "6.4" 51 | - groupId: "org.jenkins-ci.plugins" 52 | artifactId: "credentials" 53 | source: 54 | version: "2.1.11" 55 | - groupId: "org.jenkins-ci.plugins" 56 | artifactId: "structs" 57 | source: 58 | version: "1.14" 59 | - groupId: "org.jenkins-ci.plugins" 60 | artifactId: "scm-api" 61 | source: 62 | version: "2.2.6" 63 | - groupId: "org.jenkins-ci.plugins" 64 | artifactId: "ssh-credentials" 65 | source: 66 | version: "1.12" 67 | - groupId: "org.jenkins-ci.plugins" 68 | artifactId: "credentials-binding" 69 | source: 70 | version: "1.16" 71 | - groupId: "org.jenkins-ci.plugins.workflow" 72 | artifactId: "workflow-aggregator" 73 | source: 74 | version: "2.5" 75 | - groupId: "io.jenkins" 76 | artifactId: "configuration-as-code" 77 | source: 78 | version: "1.1" 79 | systemProperties: { 80 | jenkins.model.Jenkins.slaveAgentPort: "50000", 81 | jenkins.model.Jenkins.slaveAgentPortEnforce: "true"} 82 | -------------------------------------------------------------------------------- /tests/test_resources/test_with_tag_using_cwp_docker_image/Jenkinsfile: -------------------------------------------------------------------------------- 1 | 2 | stage('Read Evergreen YAML') { 3 | node { 4 | // Discover core version using Pipeline utility steps 5 | sh 'wget https://raw.githubusercontent.com/jenkins-infra/evergreen/master/services/essentials.yaml' 6 | def essentialsYaml = readYaml(file: "essentials.yaml") 7 | echo "Jenkins Evergreen uses the following Core version: ${essentialsYaml.spec.core.version}" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/test_resources/test_with_tag_using_cwp_docker_image/packager-config.yml: -------------------------------------------------------------------------------- 1 | bundle: 2 | groupId: "io.jenkins.tools.custom-war-packager.demo" 3 | artifactId: "jenkinsfile-runner" 4 | vendor: "Jenkins project" 5 | title: "Jenkinsfile Runner demo" 6 | description: "Jenkinsfile Runner Docker Image, produced by Custom WAR Packager" 7 | buildSettings: 8 | jenkinsfileRunner: 9 | source: 10 | groupId: "io.jenkins" 11 | artifactId: "jenkinsfile-runner" 12 | build: 13 | noCache: true 14 | source: 15 | git: https://github.com/jenkinsci/jenkinsfile-runner.git 16 | branch: parent-1.0-beta-4 17 | docker: 18 | base: "jenkins/jenkins:2.138.2" 19 | tag: "jenkins-experimental/jenkinsfile-runner-demo" 20 | build: false 21 | war: 22 | groupId: "org.jenkins-ci.main" 23 | artifactId: "jenkins-war" 24 | source: 25 | version: "2.138.2" 26 | plugins: 27 | - groupId: "org.jenkins-ci.plugins.workflow" 28 | artifactId: "workflow-job" 29 | source: 30 | version: "2.24" 31 | - groupId: "org.jenkins-ci.plugins.workflow" 32 | artifactId: "workflow-cps" 33 | source: 34 | version: "2.48" 35 | - groupId: "org.jenkins-ci.plugins.workflow" 36 | artifactId: "workflow-api" 37 | source: 38 | version: "2.27" 39 | - groupId: "org.jenkins-ci.plugins.workflow" 40 | artifactId: "workflow-step-api" 41 | source: 42 | version: "2.14" 43 | - groupId: "org.jenkins-ci.plugins" 44 | artifactId: "pipeline-utility-steps" 45 | source: 46 | version: "2.1.0" 47 | - groupId: "org.jenkins-ci.plugins" 48 | artifactId: "cloudbees-folder" 49 | source: 50 | version: "6.4" 51 | - groupId: "org.jenkins-ci.plugins" 52 | artifactId: "credentials" 53 | source: 54 | version: "2.1.11" 55 | - groupId: "org.jenkins-ci.plugins" 56 | artifactId: "structs" 57 | source: 58 | version: "1.14" 59 | - groupId: "org.jenkins-ci.plugins" 60 | artifactId: "scm-api" 61 | source: 62 | version: "2.2.6" 63 | - groupId: "org.jenkins-ci.plugins" 64 | artifactId: "ssh-credentials" 65 | source: 66 | version: "1.12" 67 | - groupId: "org.jenkins-ci.plugins" 68 | artifactId: "credentials-binding" 69 | source: 70 | version: "1.16" 71 | - groupId: "org.jenkins-ci.plugins.workflow" 72 | artifactId: "workflow-aggregator" 73 | source: 74 | version: "2.5" 75 | - groupId: "io.jenkins" 76 | artifactId: "configuration-as-code" 77 | source: 78 | version: "1.1" 79 | systemProperties: { 80 | jenkins.model.Jenkins.slaveAgentPort: "50000", 81 | jenkins.model.Jenkins.slaveAgentPortEnforce: "true"} 82 | -------------------------------------------------------------------------------- /tests/tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | current_directory=$(pwd) 5 | test_framework_directory="$current_directory/.." 6 | working_directory="$current_directory/.testing" 7 | 8 | version="256.0-test" 9 | jenkinsfile_runner_tag="jenkins-experimental/jenkinsfile-runner-test-image" 10 | 11 | downloaded_cwp_jar="to_update" 12 | 13 | . $test_framework_directory/init-jfr-test-framework.inc 14 | 15 | oneTimeSetUp() { 16 | downloaded_cwp_jar=$(download_cwp "$working_directory") 17 | } 18 | 19 | setUp() { 20 | if [[ ${_shunit_test_} == *"using_cwp_docker_image"* ]] 21 | then 22 | set_timeout 900 23 | else 24 | set_timeout -1 25 | fi 26 | } 27 | 28 | test_with_tag() { 29 | jfr_tag=$(execute_cwp_jar_and_generate_docker_image "$working_directory" "$downloaded_cwp_jar" "$version" "$current_directory/test_resources/test_with_tag/packager-config.yml" "$jenkinsfile_runner_tag" | grep 'Successfully tagged') 30 | execution_should_success "$?" "$jenkinsfile_runner_tag" "$jfr_tag" 31 | 32 | run_jfr_docker_image "$jenkinsfile_runner_tag" "$current_directory/test_resources/test_with_tag/Jenkinsfile" 33 | jenkinsfile_execution_should_succeed "$?" 34 | } 35 | 36 | test_java_opts() { 37 | jfr_tag=$(execute_cwp_jar_and_generate_docker_image "$working_directory" "$downloaded_cwp_jar" "$version" "$current_directory/test_resources/test_with_tag/packager-config.yml" "$jenkinsfile_runner_tag" | grep 'Successfully tagged') 38 | execution_should_success "$?" "$jenkinsfile_runner_tag" "$jfr_tag" 39 | 40 | run_jfr_docker_image "$jenkinsfile_runner_tag" "$current_directory/test_resources/test_with_tag/Jenkinsfile" 41 | jenkinsfile_execution_should_succeed "$?" 42 | 43 | export JAVA_OPTS="-Xmx1M -Xms100G" 44 | run_jfr_docker_image "$jenkinsfile_runner_tag" "$current_directory/test_resources/test_with_tag/Jenkinsfile" 45 | assertEquals "Should retrieve exit code 0" "0" "$?" 46 | logs_not_contains "[Pipeline] End of Pipeline" 47 | logs_not_contains "Finished: SUCCESS" 48 | logs_contains "Initial heap size set to a larger value than the maximum heap size" 49 | unset JAVA_OPTS 50 | } 51 | 52 | test_with_default_tag() { 53 | jfr_tag=$(execute_cwp_jar_and_generate_docker_image "$working_directory" "$downloaded_cwp_jar" "$version" "$current_directory/test_resources/test_with_tag/packager-config.yml" | grep 'Successfully tagged') 54 | execution_should_success "$?" "test_with_default_tag" "$jfr_tag" 55 | } 56 | 57 | test_download_cwp_version() { 58 | test_download_working_directory="$working_directory/test_download_cwp_version" 59 | rm -rf "$test_download_working_directory" 60 | mkdir "$test_download_working_directory" 61 | default_cwp_jar=$(download_cwp "$test_download_working_directory") 62 | execution_should_success "$?" "cwp-cli-$DEFAULT_CWP_VERSION.jar" "$default_cwp_jar" 63 | 64 | another_cwp_jar=$(download_cwp "$test_download_working_directory" "1.3") 65 | execution_should_success "$?" "cwp-cli-1.3.jar" "$another_cwp_jar" 66 | } 67 | 68 | test_with_tag_using_cwp_docker_image() { 69 | jfr_tag=$(generate_docker_image_from_cwp_docker_image "$current_directory/test_resources/test_with_tag_using_cwp_docker_image/packager-config.yml" "$jenkinsfile_runner_tag" | grep 'Successfully tagged') 70 | execution_should_success "$?" "$jenkinsfile_runner_tag" "$jfr_tag" 71 | 72 | run_jfr_docker_image "$jenkinsfile_runner_tag" "$current_directory/test_resources/test_with_tag_using_cwp_docker_image/Jenkinsfile" 73 | jenkinsfile_execution_should_succeed "$?" 74 | } 75 | 76 | test_with_default_tag_using_cwp_docker_image() { 77 | jfr_tag=$(generate_docker_image_from_cwp_docker_image "$current_directory/test_resources/test_with_default_tag_using_cwp_docker_image/packager-config.yml" | grep 'Successfully tagged') 78 | execution_should_success "$?" "test_with_default_tag_using_cwp_docker_image" "$jfr_tag" 79 | } 80 | 81 | test_failing_docker_image() { 82 | result=$(execute_cwp_jar_and_generate_docker_image "$working_directory" "$downloaded_cwp_jar" "$version" "$current_directory/test_resources/test_failing_docker_image/packager-config.yml") 83 | docker_generation_should_fail "$?" "$result" 84 | } 85 | 86 | test_jenkinsfile_fail() { 87 | jfr_tag=$(execute_cwp_jar_and_generate_docker_image "$working_directory" "$downloaded_cwp_jar" "$version" "$current_directory/test_resources/test_with_tag/packager-config.yml" "$jenkinsfile_runner_tag" | grep 'Successfully tagged') 88 | execution_should_success "$?" "$jenkinsfile_runner_tag" "$jfr_tag" 89 | 90 | run_jfr_docker_image "$jenkinsfile_runner_tag" "$current_directory/test_resources/test_jenkinsfile_fail/Jenkinsfile" 91 | jenkinsfile_execution_should_fail "$?" 92 | } 93 | 94 | test_jenkinsfile_unstable() { 95 | jfr_tag=$(execute_cwp_jar_and_generate_docker_image "$working_directory" "$downloaded_cwp_jar" "$version" "$current_directory/test_resources/test_with_tag/packager-config.yml" "$jenkinsfile_runner_tag" | grep 'Successfully tagged') 96 | execution_should_success "$?" "$jenkinsfile_runner_tag" "$jfr_tag" 97 | 98 | run_jfr_docker_image "$jenkinsfile_runner_tag" "$current_directory/test_resources/test_jenkinsfile_unstable/Jenkinsfile" 99 | jenkinsfile_execution_should_be_unstable "$?" 100 | } 101 | 102 | test_all_hooks() { 103 | build_result=$(generate_docker_image_from_cwp_docker_image "$current_directory/test_resources/test_all_hooks/packager-config.yml" "$jenkinsfile_runner_tag" | grep 'Successfully tagged') 104 | execution_should_success "$?" "$jenkinsfile_runner_tag" "$build_result" 105 | 106 | export JAVA_OPTS="-Djenkins.model.Jenkins.workspacesDir=/build" 107 | 108 | run_jfr_docker_image_with_docker_options "$jenkinsfile_runner_tag" "$current_directory/test_resources/test_all_hooks/Jenkinsfile" "-v $working_directory/files:/build" 109 | 110 | jenkinsfile_execution_should_succeed "$?" 111 | logs_contains "This is the message to find in the logs" 112 | file_contains_text "This is the message to find in the logs" "message.txt" "$working_directory/files" 113 | 114 | unset JAVA_OPTS 115 | } 116 | 117 | test_with_jfr_options() { 118 | jfr_tag=$(execute_cwp_jar_and_generate_docker_image "$working_directory" "$downloaded_cwp_jar" "$version" "$current_directory/test_resources/test_with_jfr_options/packager-config.yml" "$jenkinsfile_runner_tag" | grep 'Successfully tagged') 119 | execution_should_success "$?" "$jenkinsfile_runner_tag" "$jfr_tag" 120 | 121 | param="-a param1=Hello" 122 | run_jfr_docker_image_with_jfr_options "$jenkinsfile_runner_tag" "$current_directory/test_resources/test_with_jfr_options/Jenkinsfile" "$param" 123 | jenkinsfile_execution_should_succeed "$?" 124 | logs_contains "Value for param1: Hello" 125 | } 126 | 127 | init_framework -------------------------------------------------------------------------------- /tests/timeout-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | current_directory=$(pwd) 5 | test_framework_directory="$current_directory/.." 6 | working_directory="$current_directory/.testing" 7 | 8 | version="256.0-test" 9 | jenkinsfile_runner_tag="jenkins-experimental/jenkinsfile-runner-test-image" 10 | 11 | . $test_framework_directory/init-jfr-test-framework.inc 12 | 13 | setUp() { 14 | downloaded_cwp_jar=$(download_cwp "$working_directory") 15 | execute_cwp_jar_and_generate_docker_image "$working_directory" "$downloaded_cwp_jar" "$version" "$current_directory/test_resources/test_with_tag/packager-config.yml" "$jenkinsfile_runner_tag" | grep 'Successfully tagged' 16 | } 17 | 18 | test_timeout() { 19 | run_jfr_docker_image "$jenkinsfile_runner_tag" "$current_directory/test_resources/test_timeout/Jenkinsfile" 20 | jenkinsfile_execution_should_succed "$?" 21 | } 22 | 23 | # Prepare docker image 24 | setUp 25 | 26 | # Set timeout value to 10 seconds 27 | set_timeout 10 28 | 29 | # Eval the timeout 30 | set +e 31 | result=$(eval run_with_timeout "test_timeout" | grep "[ERROR]*timeout") 32 | set -e 33 | 34 | # Print result 35 | if [[ "$result" != *"[ERROR] test_timeout timeout. Passed 10 seconds"* ]] 36 | then 37 | echo "test FAIL: test_timeout should timeout" 38 | echo "1 test executed" 39 | else 40 | echo "test OK" 41 | echo "1 test executed" 42 | fi 43 | -------------------------------------------------------------------------------- /tests/workspace_hook_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | current_directory=$(pwd) 5 | test_framework_directory="$current_directory/.." 6 | testing_directory="$current_directory/.testing" 7 | working_directory="$testing_directory/workspace-test" 8 | test_file="test.txt" 9 | 10 | . $test_framework_directory/init-jfr-test-framework.inc 11 | 12 | oneTimeSetUp() { 13 | # Removing should not be necessary 14 | rm -rf "$working_directory" 15 | mkdir -p "$working_directory" 16 | echo "This is a fake text in a test file" > "$working_directory/$test_file" 17 | export WORKSPACE="$working_directory" 18 | } 19 | 20 | oneTimeTearDown() { 21 | rm -rf "$working_directory" 22 | unset WORKSPACE 23 | } 24 | 25 | test_workspace_exists() { 26 | # Passing another directory to check if exist so we do not use the WORKSPACE environment variable 27 | workspace_exists "$test_framework_directory" 28 | } 29 | 30 | test_workspace_does_not_exist() { 31 | workspace_does_not_exist "$working_directory/fake_directory" 32 | } 33 | 34 | test_file_exists_in_workspace() { 35 | file_exists_in_workspace "$test_file" 36 | } 37 | 38 | test_file_does_not_exist_in_workspace() { 39 | file_does_not_exist_in_workspace fake_file.txt 40 | } 41 | 42 | test_file_contains_text() { 43 | file_contains_text "fake text" "$test_file" 44 | } 45 | 46 | test_file_does_not_contains_text() { 47 | file_does_not_contains_text "unexpected text" "$test_file" 48 | } 49 | 50 | init_framework 51 | --------------------------------------------------------------------------------