From 997761071b5ce8a073c5888b32d1221d2a231cfa Mon Sep 17 00:00:00 2001 From: caill34 <91425014+caill34@users.noreply.github.com> Date: Tue, 23 Nov 2021 18:12:28 +0000 Subject: [PATCH 1/9] Delete README.md --- README.md | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index e89024b..0000000 --- a/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# simple-python-pyinstaller-app - -This repository is for the -[Build a Python app with PyInstaller](https://jenkins.io/doc/tutorials/build-a-python-app-with-pyinstaller/) -tutorial in the [Jenkins User Documentation](https://jenkins.io/doc/). - -The repository contains a simple Python application which is a command line tool "add2vals" that outputs the addition of two values. If at least one of the -values is a string, "add2vals" treats both values as a string and instead -concatenates the values. The "add2" function in the "calc" library (which -"add2vals" imports) is accompanied by a set of unit tests. These are tested with pytest to check that this function works as expected and the results are saved -to a JUnit XML report. - -The delivery of the "add2vals" tool through PyInstaller converts this tool into -a standalone executable file for Linux, which you can download through Jenkins -and execute at the command line on Linux machines without Python. - -The `jenkins` directory contains an example of the `Jenkinsfile` (i.e. Pipeline) -you'll be creating yourself during the tutorial. From f039252986c51ef6d99120c06392cd3806a9e5ee Mon Sep 17 00:00:00 2001 From: caill34 <91425014+caill34@users.noreply.github.com> Date: Tue, 23 Nov 2021 19:59:49 +0000 Subject: [PATCH 2/9] Create Jenkinsfile Add initial Jenkinsfile --- Jenkinsfile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..2bc3ea8 --- /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' + stash(name: 'compiled-results', includes: 'sources/*.py*') + } + } + } +} From 8557a61bc59995cc6d261e294cce0fe8939cc808 Mon Sep 17 00:00:00 2001 From: caill34 <91425014+caill34@users.noreply.github.com> Date: Tue, 23 Nov 2021 20:19:10 +0000 Subject: [PATCH 3/9] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2bc3ea8..41a334e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,7 +8,7 @@ pipeline { } } steps { - sh 'python -m py_compile sources/add2vals.py sources/calc.py' + sh 'python -m py_compile sources/helloworld.py' stash(name: 'compiled-results', includes: 'sources/*.py*') } } From 682de0bf4cc5fc08d8db4818a35a959ad158a89e Mon Sep 17 00:00:00 2001 From: caill34 <91425014+caill34@users.noreply.github.com> Date: Tue, 23 Nov 2021 20:19:12 +0000 Subject: [PATCH 4/9] Delete add2vals.py --- sources/add2vals.py | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 sources/add2vals.py diff --git a/sources/add2vals.py b/sources/add2vals.py deleted file mode 100644 index d671e38..0000000 --- a/sources/add2vals.py +++ /dev/null @@ -1,25 +0,0 @@ -''' -A simple command line tool that takes 2 values and adds them together using -the calc.py library's 'add2' function. -''' - -import sys -import calc - -argnumbers = len(sys.argv) - 1 - -if argnumbers == 2 : - print("") - print("The result is " + str(calc.add2(str(sys.argv[1]), str(sys.argv[2])))) - print("") - sys.exit(0) - -if argnumbers != 2 : - print("") - print("You entered " + str(argnumbers) + " value/s.") - print("") - print("Usage: 'add2vals X Y' where X and Y are individual values.") - print(" If add2vals is not in your path, usage is './add2vals X Y'.") - print(" If unbundled, usage is 'python add2vals.py X Y'.") - print("") - sys.exit(1) From b5cb1a989ae13fa1d0d73ecb4399821f83855ed1 Mon Sep 17 00:00:00 2001 From: caill34 <91425014+caill34@users.noreply.github.com> Date: Tue, 23 Nov 2021 20:19:14 +0000 Subject: [PATCH 5/9] Delete calc.py --- sources/calc.py | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 sources/calc.py diff --git a/sources/calc.py b/sources/calc.py deleted file mode 100644 index 368c55b..0000000 --- a/sources/calc.py +++ /dev/null @@ -1,28 +0,0 @@ -''' -The 'calc' library contains the 'add2' function that takes 2 values and adds -them together. If either value is a string (or both of them are) 'add2' ensures -they are both strings, thereby resulting in a concatenated result. -NOTE: If a value submitted to the 'add2' function is a float, it must be done so -in quotes (i.e. as a string). -''' - -# If 'value' is not an integer, convert it to a float and failing that, a string. -def conv(value): - try: - return int(value) - except ValueError: - try: - return float(value) - except ValueError: - return str(value) - -# The 'add2' function itself -def add2(arg1, arg2): - # Convert 'arg1' and 'arg2' to their appropriate types - arg1conv = conv(arg1) - arg2conv = conv(arg2) - # If either 'arg1' or 'arg2' is a string, ensure they're both strings. - if isinstance(arg1conv, str) or isinstance(arg2conv, str): - arg1conv = str(arg1conv) - arg2conv = str(arg2conv) - return arg1conv + arg2conv From 10c690cda5fb03ce9f1cd341ef8e7984b71ce4ed Mon Sep 17 00:00:00 2001 From: caill34 <91425014+caill34@users.noreply.github.com> Date: Tue, 23 Nov 2021 20:19:17 +0000 Subject: [PATCH 6/9] Create helloWorld.py --- sources/helloWorld.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 sources/helloWorld.py diff --git a/sources/helloWorld.py b/sources/helloWorld.py new file mode 100644 index 0000000..442659b --- /dev/null +++ b/sources/helloWorld.py @@ -0,0 +1 @@ +print("Hello world!") \ No newline at end of file From e73da6fa7df4481d293ca2689de95688684d2615 Mon Sep 17 00:00:00 2001 From: caill34 <91425014+caill34@users.noreply.github.com> Date: Tue, 23 Nov 2021 20:19:19 +0000 Subject: [PATCH 7/9] Delete test_calc.py --- sources/test_calc.py | 48 -------------------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 sources/test_calc.py diff --git a/sources/test_calc.py b/sources/test_calc.py deleted file mode 100644 index 130f9f7..0000000 --- a/sources/test_calc.py +++ /dev/null @@ -1,48 +0,0 @@ -import unittest -import calc - -class TestCalc(unittest.TestCase): - """ - Test the add function from the calc library - """ - - 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 e09fa8291fc237cbe7e296ac445be638d3430e72 Mon Sep 17 00:00:00 2001 From: caill34 <91425014+caill34@users.noreply.github.com> Date: Tue, 23 Nov 2021 20:20:54 +0000 Subject: [PATCH 8/9] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 41a334e..549d184 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,7 +8,7 @@ pipeline { } } steps { - sh 'python -m py_compile sources/helloworld.py' + sh 'python -m py_compile sources/helloWorld.py' stash(name: 'compiled-results', includes: 'sources/*.py*') } } From 28ce92c0c4242ea0ffa41f45557cd45f09c74b4a Mon Sep 17 00:00:00 2001 From: caill34 <91425014+caill34@users.noreply.github.com> Date: Wed, 24 Nov 2021 11:51:05 +0000 Subject: [PATCH 9/9] Update helloWorld.py Added more code --- sources/helloWorld.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sources/helloWorld.py b/sources/helloWorld.py index 442659b..8917a09 100644 --- a/sources/helloWorld.py +++ b/sources/helloWorld.py @@ -1 +1,2 @@ -print("Hello world!") \ No newline at end of file +print("Hello world!") +print("Adding more code") \ No newline at end of file