-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33bd192
commit 5e231aa
Showing
20 changed files
with
419 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
## Things to improve | ||
|
||
- [ ] CLI interface to add configuration, tasks, etc. | ||
- [ ] Healthcheck not working properly in dockercompose | ||
- [ ] Healthcheck not working properly in dockercompose | ||
- [ ] Fix Github Actions Tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/bash | ||
|
||
# Execute the python script | ||
# Execute the main script | ||
python3 /app/build.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
jenkins: | ||
systemMessage: "Jenkins configured by JCasC" | ||
plugins: | ||
required: | ||
- git | ||
- workflow-aggregator | ||
- pipeline | ||
- docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import os | ||
|
||
import src.local.main.config as config_module | ||
import src.local.main.services as services | ||
from src.local.main.services import CredentialsType | ||
|
||
try: | ||
print(f"JENKINS INFO -> Jenkins URL: {config_module.get(config_module.ConfigKeys.JENKINS_URL)}, Username: {config_module.get(config_module.ConfigKeys.JENKINS_USER)}, API Token: {config_module.get(config_module.ConfigKeys.JENKINS_PASS)}") | ||
|
||
# Jenkins version | ||
user = services.jenkins_service.get_whoami() | ||
version = services.jenkins_service.get_version() | ||
print('JENKINS INFO -> Hello %s from Jenkins %s' % (user['fullName'], version)) | ||
|
||
# Print all files in the current directory | ||
print(os.listdir('.')) | ||
|
||
# Configured on docker-compose (check volumes) | ||
if config_module.ENV == 'env.local': | ||
path_job = '../.data/Jenkinsfile_spring.xml' | ||
else: | ||
path_job = './data/Jenkinsfile_spring.xml' | ||
|
||
# List all content dir | ||
if config_module.ENV != 'env.local': | ||
try: | ||
content = os.listdir('../') | ||
print(content) | ||
except Exception as e: | ||
print(e) | ||
|
||
# Read XML job | ||
job_config = open(path_job).read() | ||
|
||
# Create credentials | ||
services.build_credentials(CredentialsType.USER) | ||
|
||
job_name = "spring-pipeline" | ||
|
||
try: | ||
if services.jenkins_service.job_exists(job_name): | ||
services.jenkins_service.delete_job(job_name) | ||
print(f'Job {job_name} already exists and was deleted') | ||
else: | ||
print(f'Job {job_name} does not exist') | ||
services.jenkins_service.create_job(job_name, job_config) | ||
print('Job created successfully') | ||
except Exception as e: | ||
print(e) | ||
|
||
services.jenkins_service.build_job(job_name) | ||
print('Job execute successfully') | ||
except Exception as e: | ||
print("Error: ", e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
from dotenv import dotenv_values | ||
|
||
from enum import Enum | ||
|
||
class ConfigKeys(str, Enum): | ||
JENKINS_URL = 'JENKINS_URL' | ||
JENKINS_USER = 'JENKINS_USER' | ||
JENKINS_PASS = 'JENKINS_PASS' | ||
PAT_JENKINS = 'PAT_JENKINS' | ||
JENKINS_CREDENTIALS_ID = 'JENKINS_CREDENTIALS_ID' | ||
|
||
|
||
# Global variables | ||
config = {} | ||
ENV = os.getenv('ENV') # Provided by Github Actions or Environment Variables | ||
if ENV == 'prod': | ||
env_files_path = '<cloud-config>' | ||
else: | ||
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../..')) | ||
env_files_path = os.path.join(project_root, '.env', f'env.{ENV}') | ||
ENV = 'local' | ||
|
||
# TODO - This is a hack to get around the fact that the sensitive data is not injected through the gitlab pipeline | ||
config = dotenv_values(env_files_path) | ||
|
||
if ENV == 'prod': | ||
# Jenkins connection details | ||
jenkins_url = os.getenv(ConfigKeys.JENKINS_URL.value) | ||
jenkins_username = os.getenv(ConfigKeys.JENKINS_USER.value) | ||
jenkins_password = os.getenv(ConfigKeys.JENKINS_PASS.value) # Get it from Jenkins > User > Configure | ||
jenkins_pat_token = os.getenv(ConfigKeys.PAT_JENKINS.value) | ||
jenkins_credentials_id = os.getenv(ConfigKeys.JENKINS_CREDENTIALS_ID.value) | ||
|
||
# Storing values in the config dictionary | ||
config[ConfigKeys.JENKINS_URL.value] = jenkins_url | ||
config[ConfigKeys.JENKINS_USER.value] = jenkins_username | ||
config[ConfigKeys.JENKINS_PASS.value] = jenkins_password | ||
config[ConfigKeys.PAT_JENKINS.value] = jenkins_pat_token | ||
config[ConfigKeys.JENKINS_CREDENTIALS_ID.value] = jenkins_credentials_id | ||
|
||
def get(key: str) -> str: | ||
return config.get(key) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.