diff --git a/Jenkinsfile1 b/Jenkinsfile1 new file mode 100644 index 000000000..32192ecb2 --- /dev/null +++ b/Jenkinsfile1 @@ -0,0 +1,13 @@ +node { + stage('Checkout') { + checkout scm + } + + stage('Build') { + sh 'python3 build_script.py' + } + + stage('Test') { + sh 'python3 test_script.py' + } +} diff --git a/build_script.py b/build_script.py new file mode 100644 index 000000000..f123652ea --- /dev/null +++ b/build_script.py @@ -0,0 +1,21 @@ +import subprocess +import sys + +def install_dependencies(): + try: + print("Installing dependencies...") + subprocess.run([sys.executable, "-m", "venv", "venv"], check=True) + subprocess.run(["venv/bin/python", "-m", "pip", "install", "-r", "requirements.txt"], check=True) + print("Dependencies installed successfully!") + except subprocess.CalledProcessError as e: + print(f"Error: {e}") + sys.exit(1) + +def main(): + print("Building the Python project...") + install_dependencies() + # Add additional build steps as needed + print("Build completed successfully!") + +if __name__ == "__main__": + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..7f2f5a819 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +certifi>=2017.4.17 +chardet>=3.0.2,<4 +idna>=2.5,<3 +urllib3>=1.21.1,<1.26,!=1.25.1,!=1.25.0 diff --git a/script-pipeline.txt b/script-pipeline.txt new file mode 100644 index 000000000..fa996fbde --- /dev/null +++ b/script-pipeline.txt @@ -0,0 +1,29 @@ +pipeline { + agent any + + stages { + stage('Checkout') { + steps { + script { + git branch: 'python-app', url: 'https://github.com/syahrulrzk/a428-cicd-labs.git' + } + } + } + + stage('Build') { + steps { + script { + sh 'python3 build_script.py' + } + } + } + + stage('Test') { + steps { + script { + sh 'python3 test_script.py' + } + } + } + } +} diff --git a/test_script.py b/test_script.py new file mode 100644 index 000000000..c29950791 --- /dev/null +++ b/test_script.py @@ -0,0 +1,11 @@ +# your_test_script.py + +import unittest + +class TestYourApp(unittest.TestCase): + + def test_example(self): + self.assertTrue(True, "Example test passed!") + +if __name__ == "__main__": + unittest.main()