From e9d274845ed06468090a90d74c16de40628d8280 Mon Sep 17 00:00:00 2001 From: kudlaty Date: Wed, 21 Mar 2018 11:04:07 +0100 Subject: [PATCH 01/10] feature/jenkinsfile first version of Jenkinsfile --- Jenkinsfile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..a018aab --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,16 @@ +pipeline{ + agent none + stages { + stage('Build'){ + agent { + docker { + image 'python:2-alpine' + } + } + steps { + sh 'python -m py_compile sources/add2vals.py sources/calc.py' + } + } + } + +} \ No newline at end of file From 01cf027d2466c89e5918ceafc0c4e85405dd626e Mon Sep 17 00:00:00 2001 From: kudlaty Date: Wed, 21 Mar 2018 16:25:32 +0100 Subject: [PATCH 02/10] feature/jenkinsfile Test stage added --- Jenkinsfile | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index a018aab..b4fc4fb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,7 @@ pipeline{ agent none stages { - stage('Build'){ + stage('Build') { agent { docker { image 'python:2-alpine' @@ -11,6 +11,22 @@ pipeline{ sh 'python -m py_compile sources/add2vals.py sources/calc.py' } } + stage('Test') { + agent { + docker { + image 'qnib/pytest' + } + } + steps { + sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_calc.py' + } + post { + always { + junit 'test-reports/results.xml' + } + } + } } + } \ No newline at end of file From 6921b801a69c440e87043366505f67acf25f12c4 Mon Sep 17 00:00:00 2001 From: kudlaty Date: Wed, 21 Mar 2018 16:37:35 +0100 Subject: [PATCH 03/10] feature/jenkinsfile testing fail --- sources/test_calc.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sources/test_calc.py b/sources/test_calc.py index 130f9f7..f6eb309 100644 --- a/sources/test_calc.py +++ b/sources/test_calc.py @@ -5,6 +5,8 @@ class TestCalc(unittest.TestCase): """ Test the add function from the calc library """ + def test_fail(self): + self.assertFalse(True, msg="This is failed test") def test_add_integers(self): """ From c5c2993914db9d698f2a50bac184ea993b5c5ccf Mon Sep 17 00:00:00 2001 From: kudlaty Date: Wed, 21 Mar 2018 16:53:35 +0100 Subject: [PATCH 04/10] feature/jenkinsfile testing fail --- Jenkinsfile | 4 ++-- sources/test_calc.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b4fc4fb..cf6001d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,7 +4,7 @@ pipeline{ stage('Build') { agent { docker { - image 'python:2-alpine' + image 'python:3-alpine' } } steps { @@ -18,7 +18,7 @@ pipeline{ } } steps { - sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_calc.py' + sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_calc.py || true' } post { always { diff --git a/sources/test_calc.py b/sources/test_calc.py index f6eb309..58f3ffc 100644 --- a/sources/test_calc.py +++ b/sources/test_calc.py @@ -5,8 +5,8 @@ class TestCalc(unittest.TestCase): """ Test the add function from the calc library """ - def test_fail(self): - self.assertFalse(True, msg="This is failed test") + # def test_fail(self): + # self.assertFalse(True, msg="This is failed test") def test_add_integers(self): """ From 281af35fb9691bffadccff51b401ec222e02c507 Mon Sep 17 00:00:00 2001 From: kudlaty Date: Wed, 21 Mar 2018 17:13:25 +0100 Subject: [PATCH 05/10] feature/jenkinsfile Added deliver stage --- Jenkinsfile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index cf6001d..9293122 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,6 +26,21 @@ pipeline{ } } } + stage('Deliver') { + agent { + docker { + image 'cdrx/pyinstaller-linux:python2' + } + } + steps { + sh 'pyinstaller --onefile sources/add2vals.py' + } + post { + success { + archiveArtifacts 'dist/add2vals' + } + } + } } From 707914f3eff628d542be1a3dbd78a8b1fa028ef1 Mon Sep 17 00:00:00 2001 From: kudlaty Date: Wed, 21 Mar 2018 17:21:03 +0100 Subject: [PATCH 06/10] feature/jenkinsfile Added input step --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 9293122..73a2c0f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -34,6 +34,7 @@ pipeline{ } steps { sh 'pyinstaller --onefile sources/add2vals.py' + input message: "Build stage finished.(click to preceded)" } post { success { From 2534a6413f9d57b4098eb5f27fca3bd92a35995f Mon Sep 17 00:00:00 2001 From: kudlaty Date: Wed, 21 Mar 2018 19:13:52 +0100 Subject: [PATCH 07/10] feature/jenkinsfile added parallel tests --- Jenkinsfile | 46 +++++++++++++++++++++++++++++---------- sources/test_calc.py | 42 ++++++++++++++++++------------------ sources/test_calc2.py | 50 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 32 deletions(-) create mode 100644 sources/test_calc2.py diff --git a/Jenkinsfile b/Jenkinsfile index 73a2c0f..ce6010b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,19 +12,43 @@ pipeline{ } } stage('Test') { - agent { - docker { - image 'qnib/pytest' + + parallel { + stage('on centos') { + agent { + docker { + image 'qnib/pytest' + } + } + steps { + sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_calc.py || true' + } + post { + always { + junit 'test-reports/results.xml' + } + } } - } - steps { - sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_calc.py || true' - } - post { - always { - junit 'test-reports/results.xml' + stage('on debian') { + agent { + docker { + image 'qnib/pytest' + } + } + steps { + sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_calc2.py || true' + } + post { + always { + junit 'test-reports/results.xml' + } + } } - } +// steps { +// sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_calc.py || true' +// } + + } } stage('Deliver') { agent { diff --git a/sources/test_calc.py b/sources/test_calc.py index 58f3ffc..fe0cbbf 100644 --- a/sources/test_calc.py +++ b/sources/test_calc.py @@ -8,27 +8,27 @@ class TestCalc(unittest.TestCase): # def test_fail(self): # self.assertFalse(True, msg="This is failed test") - def test_add_integers(self): - """ - Test that the addition of two integers returns the correct total - """ - result = calc.add2(1, 2) - self.assertEqual(result, 3) - - def test_add_floats(self): - """ - Test that the addition of two floats returns the correct result - """ - result = calc.add2('10.5', 2) - self.assertEqual(result, 12.5) - - def test_add_strings(self): - """ - Test the addition of two strings returns the two strings as one - concatenated string - """ - result = calc.add2('abc', 'def') - self.assertEqual(result, 'abcdef') + # def test_add_integers(self): + # """ + # Test that the addition of two integers returns the correct total + # """ + # result = calc.add2(1, 2) + # self.assertEqual(result, 3) + # + # def test_add_floats(self): + # """ + # Test that the addition of two floats returns the correct result + # """ + # result = calc.add2('10.5', 2) + # self.assertEqual(result, 12.5) + # + # def test_add_strings(self): + # """ + # Test the addition of two strings returns the two strings as one + # concatenated string + # """ + # result = calc.add2('abc', 'def') + # self.assertEqual(result, 'abcdef') def test_add_string_and_integer(self): """ diff --git a/sources/test_calc2.py b/sources/test_calc2.py new file mode 100644 index 0000000..28f53bc --- /dev/null +++ b/sources/test_calc2.py @@ -0,0 +1,50 @@ +import unittest +import calc + +class TestCalc(unittest.TestCase): + """ + Test the add function from the calc library + """ + # def test_fail(self): + # self.assertFalse(True, msg="This is failed test") + + def test_add_integers(self): + """ + Test that the addition of two integers returns the correct total + """ + result = calc.add2(1, 2) + self.assertEqual(result, 3) + + def test_add_floats(self): + """ + Test that the addition of two floats returns the correct result + """ + result = calc.add2('10.5', 2) + self.assertEqual(result, 12.5) + + def test_add_strings(self): + """ + Test the addition of two strings returns the two strings as one + concatenated string + """ + result = calc.add2('abc', 'def') + self.assertEqual(result, 'abcdef') + + # def test_add_string_and_integer(self): + # """ + # Test the addition of a string and an integer returns them as one + # concatenated string (in which the integer is converted to a string) + # """ + # result = calc.add2('abc', 3) + # self.assertEqual(result, 'abc3') + # + # def test_add_string_and_number(self): + # """ + # Test the addition of a string and a float returns them as one + # concatenated string (in which the float is converted to a string) + # """ + # result = calc.add2('abc', '5.5') + # self.assertEqual(result, 'abc5.5') + +if __name__ == '__main__': + unittest.main() From 2fe76a2749c4ffbf0ccc65100f735c11ac12cdfd Mon Sep 17 00:00:00 2001 From: kudlaty Date: Wed, 21 Mar 2018 19:43:02 +0100 Subject: [PATCH 08/10] feature/jenkinsfile github notify --- Jenkinsfile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ce6010b..be84bee 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,6 +8,8 @@ pipeline{ } } steps { + env.COMMIT_HASH = sh(returnStdout: true, script: 'git rev-parse HEAD').trim() + sh "echo $env.COMMIT_HASH" sh 'python -m py_compile sources/add2vals.py sources/calc.py' } } @@ -42,13 +44,11 @@ pipeline{ always { junit 'test-reports/results.xml' } + } } -// steps { -// sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_calc.py || true' -// } - } + } } stage('Deliver') { agent { @@ -59,11 +59,14 @@ pipeline{ steps { sh 'pyinstaller --onefile sources/add2vals.py' input message: "Build stage finished.(click to preceded)" + } post { success { archiveArtifacts 'dist/add2vals' + githubNotify description: 'This is a shorted example', status: 'SUCCESS' } + } } } From a9e94281940127ce0b30bcf21411070e4129238f Mon Sep 17 00:00:00 2001 From: kudlaty Date: Wed, 21 Mar 2018 20:19:39 +0100 Subject: [PATCH 09/10] feature/jenkinsfile github notify --- Jenkinsfile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index be84bee..7bb6217 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,12 @@ pipeline{ - agent none + agent any stages { + stage('env') { + steps { + sh 'printenv' + } + } + stage('Build') { agent { docker { @@ -8,8 +14,9 @@ pipeline{ } } steps { - env.COMMIT_HASH = sh(returnStdout: true, script: 'git rev-parse HEAD').trim() - sh "echo $env.COMMIT_HASH" +// checkout scm +// env.COMMIT_HASH = sh(returnStdout: true, script: 'git rev-parse HEAD').trim() + sh "git rev-parse HEAD" sh 'python -m py_compile sources/add2vals.py sources/calc.py' } } From 1679d963df5927d0b4d8fe2dc9fc4efcbd25f2cb Mon Sep 17 00:00:00 2001 From: kudlaty Date: Wed, 21 Mar 2018 20:29:52 +0100 Subject: [PATCH 10/10] feature/jenkinsfile github notify --- Jenkinsfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7bb6217..b249e71 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,9 +14,6 @@ pipeline{ } } steps { -// checkout scm -// env.COMMIT_HASH = sh(returnStdout: true, script: 'git rev-parse HEAD').trim() - sh "git rev-parse HEAD" sh 'python -m py_compile sources/add2vals.py sources/calc.py' } }