Forked from iam-veeramalla/upload_jenkins_build_logs.sh
Created
January 11, 2025 23:56
-
-
Save skpanigrahy/a0c960ed5a080d6e58d231374a288bfb to your computer and use it in GitHub Desktop.
upload_jenkins_build_logs.sh
This file contains hidden or 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
| #!/bin/bash | |
| # Variables | |
| JENKINS_HOME="/var/lib/jenkins" # Replace with your Jenkins home directory | |
| S3_BUCKET="s3://your-s3-bucket-name" # Replace with your S3 bucket name | |
| DATE=$(date +%Y-%m-%d) # Today's date | |
| # Check if AWS CLI is installed | |
| if ! command -v aws &> /dev/null; then | |
| echo "AWS CLI is not installed. Please install it to proceed." | |
| exit 1 | |
| fi | |
| # Iterate through all job directories | |
| for job_dir in "$JENKINS_HOME/jobs/"*/; do | |
| job_name=$(basename "$job_dir") | |
| # Iterate through build directories for the job | |
| for build_dir in "$job_dir/builds/"*/; do | |
| # Get build number and log file path | |
| build_number=$(basename "$build_dir") | |
| log_file="$build_dir/log" | |
| # Check if log file exists and was created today | |
| if [ -f "$log_file" ] && [ "$(date -r "$log_file" +%Y-%m-%d)" == "$DATE" ]; then | |
| # Upload log file to S3 with the build number as the filename | |
| aws s3 cp "$log_file" "$S3_BUCKET/$job_name-$build_number.log" --only-show-errors | |
| if [ $? -eq 0 ]; then | |
| echo "Uploaded: $job_name/$build_number to $S3_BUCKET/$job_name-$build_number.log" | |
| else | |
| echo "Failed to upload: $job_name/$build_number" | |
| fi | |
| fi | |
| done | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment