diff --git a/Gmail/Jenkinsfile b/Gmail/Jenkinsfile new file mode 100644 index 0000000..d38a0a9 --- /dev/null +++ b/Gmail/Jenkinsfile @@ -0,0 +1,37 @@ +pipeline { + agent any + + environment { + AWS_DEFAULT_REGION = 'ap-south-1' + AWS_ACCESS_KEY_ID = credentials('admin') + IAM_USERNAME = 'new55' + GIT_REPO_URL = 'https://github.com/rohanmane21/Python.git' + } + stages{ + stage('Adding git credentials'){ + steps { + script { + git branch: 'Testing', credentialsId: 'Git-Token', url: env.GIT_REPO_URL + } + } + } + stage('Create IAM User') { + steps { + script { + sh """ + aws iam create-user --user-name ${env.IAM_USERNAME} + """ + } + } + } + } + post{ + success{ + sh'python Gmail/success.py ' + } + failure{ + sh'python Gmail/failed.py ' + } + } + } + diff --git a/Gmail/failed.py b/Gmail/failed.py new file mode 100644 index 0000000..e50e65a --- /dev/null +++ b/Gmail/failed.py @@ -0,0 +1,28 @@ +import smtplib +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText +# Gmail account details +gmail_user = 'rohan4562002@gmail.com' # Your Gmail address +gmail_app_password = 'D3E0A81974662ABDCDDAF2E377A98D973E98' # Use the App Password generated earlier +# Email details +to_email = 'hr@technobrilliant.com' # Recipient's email address +subject = 'Rohan Mane' +message = 'Pipeline Failed.' +# Create a MIMEText object with your message +msg = MIMEMultipart() +msg['From'] = gmail_user +msg['To'] = to_email +msg['Subject'] = subject +msg.attach(MIMEText(message, 'plain')) +# Connect to Gmail's SMTP server +try: + server = smtplib.SMTP('smtp.elasticemail.com', 2525) + server.starttls() + server.login(gmail_user, gmail_app_password) + # Send the email + server.sendmail(gmail_user, to_email, msg.as_string()) + print('Email sent successfully!') +except Exception as e: + print(f'Error: {str(e)}') +finally: + server.quit() diff --git a/Gmail/success.py b/Gmail/success.py new file mode 100644 index 0000000..ea7f164 --- /dev/null +++ b/Gmail/success.py @@ -0,0 +1,28 @@ +import smtplib +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText +# Gmail account details +gmail_user = 'rohan4562002@gmail.com' # Your Gmail address +gmail_app_password = 'D3E0A81974662ABDCDDAF2E377A98D973E98' # Use the App Password generated earlier +# Email details +to_email = 'hr@technobrilliant.com' # Recipient's email address +subject = 'Rohan Mane' +message = 'Pipeline run successful.' +# Create a MIMEText object with your message +msg = MIMEMultipart() +msg['From'] = gmail_user +msg['To'] = to_email +msg['Subject'] = subject +msg.attach(MIMEText(message, 'plain')) +# Connect to Gmail's SMTP server +try: + server = smtplib.SMTP('smtp.elasticemail.com', 2525) + server.starttls() + server.login(gmail_user, gmail_app_password) + # Send the email + server.sendmail(gmail_user, to_email, msg.as_string()) + print('Email sent successfully!') +except Exception as e: + print(f'Error: {str(e)}') +finally: + server.quit() diff --git a/create_policy/Jenkinsfile b/create_policy/Jenkinsfile new file mode 100644 index 0000000..1455d38 --- /dev/null +++ b/create_policy/Jenkinsfile @@ -0,0 +1,13 @@ +pipeline { + agent any + stages { + stage('Create Policy') { + steps { + withAWS(credentials: 'admin', region: 'ap-south-1') + { + sh 'python create_policy/create_policy.py' + } + } + } + } +} diff --git a/create_policy/create_policy.py b/create_policy/create_policy.py new file mode 100644 index 0000000..db5648a --- /dev/null +++ b/create_policy/create_policy.py @@ -0,0 +1,12 @@ +import boto3 +import json + +user = boto3.client('iam') +def create_policy(): + with open('pipeline4/policy.json', 'r') as f: + policy_document = json.load(f) + response = user.create_policy( + PolicyName="All_Policy", + PolicyDocument=json.dumps(policy_document) + ) +# create_policy() diff --git a/create_policy/policy.json b/create_policy/policy.json new file mode 100644 index 0000000..cde4eac --- /dev/null +++ b/create_policy/policy.json @@ -0,0 +1,13 @@ +{ + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "Statement1", + "Effect": "Allow", + "Action": [ + "ec2:*" + ], + "Resource": "arn:aws:ec2:::*" + } + ] +} diff --git a/create_user/Jenkinsfile b/create_user/Jenkinsfile new file mode 100644 index 0000000..25709e8 --- /dev/null +++ b/create_user/Jenkinsfile @@ -0,0 +1,13 @@ +pipeline { + agent any + stages { + stage('Create IAM User') { + steps { + withAWS(credentials: 'admin', region: 'ap-south-1') + { + sh 'python create_user/create_user.py' + } + } + } + } +} diff --git a/create_user/create_user.py b/create_user/create_user.py new file mode 100644 index 0000000..fdd5abb --- /dev/null +++ b/create_user/create_user.py @@ -0,0 +1,10 @@ +import boto3 +import json + +user = boto3.client('iam') + +def create_user(): + response = user.create_user( + UserName='boburao' + ) +create_user() diff --git a/map_policy/Jenkinsfile b/map_policy/Jenkinsfile new file mode 100644 index 0000000..47bc19e --- /dev/null +++ b/map_policy/Jenkinsfile @@ -0,0 +1,13 @@ +pipeline { + agent any + stages { + stage('Create Policy') { + steps { + withAWS(credentials: 'admin', region: 'ap-south-1') + { + sh 'python map_policy/map.py' + } + } + } + } +} diff --git a/map_policy/map.py b/map_policy/map.py new file mode 100644 index 0000000..48bf8c0 --- /dev/null +++ b/map_policy/map.py @@ -0,0 +1,11 @@ + +import boto3 +import json + +user = boto3.client('iam') +def attach_policy(): + response = user.attach_user_policy( + UserName= 'boburao', + PolicyArn='arn:aws:iam::190616427825:policy/All_Policy' +) +attach_policy() diff --git a/pipeline1/Jenkinsfile b/pipeline1/Jenkinsfile new file mode 100644 index 0000000..c52d079 --- /dev/null +++ b/pipeline1/Jenkinsfile @@ -0,0 +1,35 @@ +pipeline { + agent any + + stages { + stage('Checkout') { + steps { + // This step checks out your source code from the repository. + // If your Jenkinsfile and Python script are in the same folder, it will be checked out here. + checkout scm + } + } + + stage('Run Python Script') { + steps { + script { + // Assuming your Python script is named 'my_script.py' + + // Execute the Python script using the 'sh' step + // You may need to specify the Python interpreter if it's not in the PATH + sh 'python my_script.py' + } + } + } + } + + post { + success { + echo 'Python script ran successfully' + } + + failure { + echo 'Python script execution failed' + } + } +} diff --git a/pipeline1/my_script.py b/pipeline1/my_script.py new file mode 100644 index 0000000..ad35e5a --- /dev/null +++ b/pipeline1/my_script.py @@ -0,0 +1 @@ +print("Hello World") diff --git a/pipeline1/my_script2.py b/pipeline1/my_script2.py new file mode 100644 index 0000000..2f9a147 --- /dev/null +++ b/pipeline1/my_script2.py @@ -0,0 +1 @@ +print("Hello") diff --git a/pipeline2/Jenkinsfile b/pipeline2/Jenkinsfile new file mode 100644 index 0000000..ebb16fb --- /dev/null +++ b/pipeline2/Jenkinsfile @@ -0,0 +1,31 @@ +pipeline { + agent any + + stages { + stage('Clone Repository') { + steps { + // Define the Git repository URL and credentials (if required) + script { + def gitRepoUrl = 'https://github.com/rohanmane21/Python.git' + def gitCredentialsId = 'Git-Token' // Optional, if using credentials + + // Clone the repository + checkout([$class: 'GitSCM', + branches: [[name: '*/Testing']], + doGenerateSubmoduleConfigurations: false, + extensions: [], + userRemoteConfigs: [[credentialsId: gitCredentialsId, url: gitRepoUrl]] + ]) + } + } + } + + stage("Run Python file"){ + steps{ + sh 'python test.py' + } + }// Add more stages for building, testing, deploying, etc. + } + + // Post-build actions, notifications, etc. +} diff --git a/pipeline3/Jenkinsfile b/pipeline3/Jenkinsfile new file mode 100644 index 0000000..27b44be --- /dev/null +++ b/pipeline3/Jenkinsfile @@ -0,0 +1,82 @@ +pipeline { + agent any + stages { + stage('test AWS credentials') { + steps { + withAWS(credentials: 'admin', region: 'ap-south-1') + { + sh 'python pipeline3/create_instance.py' + } + } + } + } +} +// pipeline { +// agent any +// stages { +// stage('Example') { +// steps { +// script { +// withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', +// credentialsId: 'admin', +// accessKeyVariable: 'AKIASYYM73UY4Q7QQNWO', +// secretKeyVariable: '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']]) { +// sh 'aws ec2 describe-instances --region ap-south-1' + +// } +// } +// } +// } +// } +// } +// pipeline { +// agent any + + +// stages { +// stage('Clone Repository') { +// steps { +// // Define the Git repository URL and credentials (if required) +// script { +// def gitRepoUrl = 'https://github.com/rohanmane21/Python.git' +// def gitCredentialsId = 'admin' // Optional, if using credentials +// sh 'aws ec2 describe-instances --region ap-south-1' // Clone the repository +// checkout([$class: 'GitSCM', +// branches: [[name: '*/Testing']], +// doGenerateSubmoduleConfigurations: false, +// extensions: [], +// userRemoteConfigs: [[credentialsId: gitCredentialsId, url: gitRepoUrl]] +// ]) +// } +// } +// } +// stage('Checkout') { +// steps { +// checkout scm +// } +// } + +// stage('Create EC2 Instance') { +// steps { +// sh 'python pipeline3/create_instance.py' +// } +// } +// } +// } +// al we created. + +// pipeline { +// agent any +// stages { +// stage('test AWS credentials') { +// steps { +// withAWS(credentials: 'jenkins-test-user', region: 'us-east-1') { +// sh 'echo "hello Jenkins">hello.txt' +// s3Upload acl: 'Private', bucket: 'devopslee', file: 'hello.txt' +// s3Download bucket: 'devopslee', file: 'downloadedHello.txt', path: 'hello.txt' +// sh 'cat downloadedHello.txt' +// } +// } +// } +// } +// } diff --git a/pipeline3/create_instance.py b/pipeline3/create_instance.py new file mode 100644 index 0000000..200b223 --- /dev/null +++ b/pipeline3/create_instance.py @@ -0,0 +1,38 @@ +import boto3 + +# # Get environment variables +# import os +# AWS_ACCESS_KEY_ID = os.environ.get('AKIASYYM73UY4Q7QQNWO') +# AWS_SECRET_ACCESS_KEY = os.environ.get('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') +# AWS_REGION = os.environ.get('ap-south-1' ) +# Create an EC2 client +ec2 = boto3.client('ec2') +# , region_name=AWS_REGION, aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY) + +# Define EC2 instance parameters +instance_params = { + 'ImageId': 'ami-02bb7d8191b50f4bb', + 'InstanceType': 't2.micro', + 'KeyName': 'jenkins', + 'MinCount': 1, + 'MaxCount': 1, + 'TagSpecifications':[ + { + 'ResourceType': 'instance', + 'Tags':[ + { + 'Key':'Name', + 'Value':'Ec2_user' + }, + ] + }, + ] +} + +# Create the EC2 instance +response = ec2.run_instances(**instance_params) + +# Print the instance ID +instance_id = response['Instances'][0]['InstanceId'] +print(f"EC2 instance created with ID: {instance_id}") + diff --git a/pipeline3/jenkins.pem b/pipeline3/jenkins.pem new file mode 100644 index 0000000..cffac29 --- /dev/null +++ b/pipeline3/jenkins.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAlPO/jP6Ia3xY8yJvKnXmZA1fPcO6BYCN9D+bS+88S9jSyh+m +el7rcykWA2hMB/tX4LLlzGDYhagUOXkf89vQV0eHzDG2LiqpGna2T6zylm1jm2hg +J34NV6xtt5pm9A9XJj4pBnFYPZkO2lASXSGM/1dc3GmUDlMiuokdbCv3b5aBJ/6d +E7abKc5ndDBUZjCaugm05JSKrinTWWyJkht7RfK1BOT1LlCdHo6FBR2ejVCseomH +zcFIX/RXeX//bC0IxkiJS+JEpv4LcQb8UOj9TcmLpTJUh00N3gEPVnQGbxVUZANI +UV1ayYvmqMaijxqEzPZ9t9mHKpHVTqViOXL15wIDAQABAoIBABDo2wYWn0YUh8SS +VCxt1gnluro4ThXx0iu4TNkB/8ZchxGLJkseG3ynXWhlnrwJPKC1roDVPb9upV0g +8w+sFKrT5Aa6XgQ/s5LdhzTkXWXWZUhvQPs6xCj/2jTNwoJSe4JL7DxfAbV8esMt +8+e+t1MFh/U9xyEZLwgeKMju9NgmAXX/hossz/e1Fpk+/IT6+BSzRAONCVAs0dyH +68UW5rmeZ5eqEvivxc9Bn11G1YpbeIegQWb2SsTbZ8ewPk+RGhDdTy2h5pqkvTrQ ++RNux+DCt36mDr2VEx9x2aLglMVFMj7qIr549aau+musBLdDEdf98eEtXBp/kRvZ +AwG5HwECgYEA0DNHhiYaJtRSekSBDbEZgJPIHMxghG8ZDEq8o4/j0VZP7vX46a/m ++zKKh2JtJhT9Py5pFGQgNrdOKn+d+yEHXc7n3g1I0rUzob34IDXN7tRKk1nuOwbp +jyB7tQSe5eWoTvK6yP4XYsc2bTvIyn0BfYJ0qtkO94xnmN7RWkaUTUkCgYEAtyY6 +yXwVvWZgdTnz5SAv+jrJRu5Tg1B4wlTRvwX6sroOoypkPyY7cGgubfupxGc5c8wZ +iKKezqj8uc6qNL9UrsCe4NIbOeiXfhWqhyvm6rSW6NT8EaszBgRegLHTNltjZ0v4 +nMIUR0x/RvXamKVfvAmNC5sZ7pcoL2G3cUhWGa8CgYEAoy5t8sDOYnyroFUs6TRT +jqlFgPzW8TW6Zh31uCTBJIQH5n03eMF7woqcdPw6HEz7KJgRl//aF8iYJUsc4YXD +pkzTAwFagHuxWiXw4h4JqBUP1mn4BJ+oU5vcGcbjW8Eip64ro/kzDyKgkAD5oWtU +zbCADKBP0MplMDYD1EPZXLECgYAY0OVGR7nqX+TR/Xg+o43cqfp70e8e69hw/G0v +JPBDJ1K0aRoMNHH5WSRxYpguNI5kUlNjYCWEewFDa+1EGGixBQiCDfYCcrGUM/tX +NWukgbOw+Kru+fN/7Teg2Hd19gwSAwk8tE9rGcJlKwrjhATkxaaG3A03duPLB8KD +ZvnDoQKBgE7w7o2JrR/FWaTcLOY0//ux2CXrSSkLs7xW5GZ+BAkB4JdBXODhU8/Z +mWDP/bTyqGK+GE4rcJouKx3gRKgwC6+/psOoV3OlRDwJSHFGd+mft/P5YmJhjGeD +v2qogUFSYgfX0yiV8XOrsTCAHtxQ9rXgL2Q3oHCMrvomaLvrO3rt +-----END RSA PRIVATE KEY----- diff --git a/pipeline4/Jenkinsfile b/pipeline4/Jenkinsfile new file mode 100644 index 0000000..d95393d --- /dev/null +++ b/pipeline4/Jenkinsfile @@ -0,0 +1,13 @@ +pipeline { + agent any + stages { + stage('Create Policy') { + steps { + withAWS(credentials: 'admin', region: 'ap-south-1') + { + sh 'python pipeline4/policy.py' + } + } + } + } +} diff --git a/pipeline4/policy.json b/pipeline4/policy.json new file mode 100644 index 0000000..cde4eac --- /dev/null +++ b/pipeline4/policy.json @@ -0,0 +1,13 @@ +{ + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "Statement1", + "Effect": "Allow", + "Action": [ + "ec2:*" + ], + "Resource": "arn:aws:ec2:::*" + } + ] +} diff --git a/pipeline4/policy.py b/pipeline4/policy.py new file mode 100644 index 0000000..e83f1a8 --- /dev/null +++ b/pipeline4/policy.py @@ -0,0 +1,23 @@ +import boto3 +import json + +user = boto3.client('iam') +def create_policy(): + with open('pipeline4/policy.json', 'r') as f: + policy_document = json.load(f) + response = user.create_policy( + PolicyName="All_Policy", + PolicyDocument=json.dumps(policy_document) + ) +def create_user(): + response = user.create_user( + UserName='boburao' + ) +# create_user() +def attach_policy(): + response = user.attach_user_policy( + UserName= 'boburao', + PolicyArn='arn:aws:iam::190616427825:policy/All_Policy' +) +# attach_policy() +# create_policy() diff --git a/pipeline5/Jenkinsfile b/pipeline5/Jenkinsfile new file mode 100644 index 0000000..577c0e4 --- /dev/null +++ b/pipeline5/Jenkinsfile @@ -0,0 +1,28 @@ +pipeline { + agent any + stages { + stage('Create Policy') { + steps { + withAWS(credentials: 'admin', region: 'ap-south-1') + { + echo 'Hello' + } + } + } + stage('Policy') { + steps { + build job: 'create_policy', wait: false + } + } + stage('User') { + steps { + build job: 'create_user', wait: false + } + } + stage('Map') { + steps { + build job: 'map_policy', wait: true + } + } + } +}