diff --git a/Jenkinsfile b/Jenkinsfile index 4047397..2d71517 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,8 @@ pipeline { - agent any + agent any // Use any available Jenkins agent/node environment { + // ID of the credentials we created in Jenkins for Git GIT_CREDENTIALS = 'gitea-creds' } @@ -9,6 +10,8 @@ pipeline { stage('Checkout SCM') { steps { + // Checkout the repository from Git (the Jenkinsfile's repo) + // This gives us the current code in the workspace checkout scm } } @@ -16,7 +19,11 @@ pipeline { stage('Create file') { steps { sh ''' + # Create a file named jenkis.txt + # Content includes a greeting, current date/time, and Jenkins build number echo "Hello from Jenkins! Current time is $(date), run number ${BUILD_NUMBER}" > jenkis.txt + + # Print the content to Jenkins console for visibility cat jenkis.txt ''' } @@ -24,6 +31,7 @@ pipeline { stage('Commit & Push') { steps { + // Provide Git credentials for pushing withCredentials([ usernamePassword( credentialsId: env.GIT_CREDENTIALS, @@ -32,12 +40,18 @@ pipeline { ) ]) { sh ''' + # Configure Git user for commit git config user.email "jenkins@local" git config user.name "Jenkins" + # Add the file to staging git add jenkis.txt + + # Commit with a message that includes the build number + # If there is nothing new, skip commit git commit -m "Jenkins: update jenkis.txt for run ${BUILD_NUMBER}" || echo "Nothing to commit" + # Push changes to main branch using credentials git push https://$GIT_USER:$GIT_PASS@gitea.dev.bodnarescu.ro/s_zsolt/test_git.git HEAD:main ''' }