pipeline { agent any // Use any available Jenkins agent/node environment { // ID of the credentials we created in Jenkins for Git GIT_CREDENTIALS = 'gitea-creds' } stages { stage('Checkout SCM') { steps { // Checkout the repository from Git (the Jenkinsfile's repo) // This gives us the current code in the workspace checkout scm } } 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 ''' } } stage('Commit & Push') { steps { // Provide Git credentials for pushing withCredentials([ usernamePassword( credentialsId: env.GIT_CREDENTIALS, usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS' ) ]) { 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 ''' } } } } }