Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python app #27

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
13 changes: 13 additions & 0 deletions Jenkinsfile1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
node {
stage('Checkout') {
checkout scm
}

stage('Build') {
sh 'python3 build_script.py'
}

stage('Test') {
sh 'python3 test_script.py'
}
}
21 changes: 21 additions & 0 deletions build_script.py
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions script-pipeline.txt
Original file line number Diff line number Diff line change
@@ -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'
}
}
}
}
}
11 changes: 11 additions & 0 deletions test_script.py
Original file line number Diff line number Diff line change
@@ -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()