Update Jenkinsfile

This commit is contained in:
2026-02-05 17:52:52 +00:00
parent bb8d523f47
commit e43b6b8c75

16
Jenkinsfile vendored
View File

@@ -1,7 +1,8 @@
pipeline { pipeline {
agent any agent any // Use any available Jenkins agent/node
environment { environment {
// ID of the credentials we created in Jenkins for Git
GIT_CREDENTIALS = 'gitea-creds' GIT_CREDENTIALS = 'gitea-creds'
} }
@@ -9,6 +10,8 @@ pipeline {
stage('Checkout SCM') { stage('Checkout SCM') {
steps { steps {
// Checkout the repository from Git (the Jenkinsfile's repo)
// This gives us the current code in the workspace
checkout scm checkout scm
} }
} }
@@ -16,7 +19,11 @@ pipeline {
stage('Create file') { stage('Create file') {
steps { steps {
sh ''' 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 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 cat jenkis.txt
''' '''
} }
@@ -24,6 +31,7 @@ pipeline {
stage('Commit & Push') { stage('Commit & Push') {
steps { steps {
// Provide Git credentials for pushing
withCredentials([ withCredentials([
usernamePassword( usernamePassword(
credentialsId: env.GIT_CREDENTIALS, credentialsId: env.GIT_CREDENTIALS,
@@ -32,12 +40,18 @@ pipeline {
) )
]) { ]) {
sh ''' sh '''
# Configure Git user for commit
git config user.email "jenkins@local" git config user.email "jenkins@local"
git config user.name "Jenkins" git config user.name "Jenkins"
# Add the file to staging
git add jenkis.txt 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" 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 git push https://$GIT_USER:$GIT_PASS@gitea.dev.bodnarescu.ro/s_zsolt/test_git.git HEAD:main
''' '''
} }