You can find configuration files in Jenkins home folder (e.g. /var/lib/jenkins
).
To keep them in VCS, first login as Jenkins (sudo su - jenkins
) and create its git credentials:
git config --global user.name "Jenkins"
git config --global user.email "jenkins@example.com"
Then initialize, add and commit the basic files such as:
git init
git add config.xml jobs/ .gitconfig
git commit -m Adds Jenkins config files -a
also consider creating .gitignore
with the following files to ignore (customize as needed):
# Git untracked files to ignore.
# Cache.
.cache/
# Fingerprint records.
fingerprints/
# Working directories.
workspace/
# Secret files.
secrets/
secret.*
*.enc
*.key
users/
id_rsa
# Plugins.
plugins/
# State files.
*.state
# Job state files.
builds/
lastStable
lastSuccessful
nextBuildNumber
# Updates.
updates/
# Hidden files.
.*
# Except git config files.
!.git*
!.ssh/
# User content.
userContent/
# Log files.
logs/
*.log
# Miscellaneous litter
*.tmp
*.old
*.bak
*.jar
*.json
*.lastExecVersion
Then add it: git add .gitignore
.
When done, you can add job config files, e.g.
shopt -s globstar
git add **/config.xml
git commit -m Added job config files -a
Finally add and commit any other files if needed, then push it to the remote repository where you want to keep the config files.
When Jenkins files are updated, you need to reload them (Reload Configuration from Disk) or run reload-configuration
from Jenkins CLI.