Files
test/Jenkinsfile
2025-10-17 12:53:57 +02:00

44 lines
1.6 KiB
Groovy

pipeline {
agent any
environment {
GIT_CREDENTIALS = 'jenkins-gitea-karel-token' // the ID of your Jenkins Gitea credentials
}
stages {
stage('Checkout') {
steps {
// Clone repo
git branch: 'main', credentialsId: env.GIT_CREDENTIALS, url: 'https://git.karel.one/karel/test.git'
}
}
stage('Modify File') {
steps {
script {
// Append a line to test.txt (create if it doesn't exist)
def file = 'test.txt'
if (!fileExists(file)) {
writeFile file: file, text: 'This is the first line\n'
} else {
writeFile file: file, text: readFile(file) + "Updated by Jenkins at ${new Date()}\n"
}
}
}
}
stage('Commit & Push') {
steps {
withCredentials([usernamePassword(
credentialsId: env.GIT_CREDENTIALS,
usernameVariable: 'GIT_USER',
passwordVariable: 'GIT_PASS'
)]) {
sh '''
git config user.name "jenkins"
git config user.email "jenkins@example.com"
git add test.txt
git commit -m "Update test.txt from Jenkins" || echo "No changes to commit"
git push https://$GIT_USER:$GIT_PASS@git.karel.one/karel/test.git main
'''
}
}
}
}
}