.gitignore is not working in jenkins jobs and unnecesary folders/fields are being included in the repo

We have Jenkins in a Windows server and several jobs are connected to one GH repo and retrieving changes from some SF orgs.
Everything works fine except for a couple of folders that must not be included in the repo, but the Jenkins jobs include them in the repo when they are executed. Those folders contain local config files that are different for each developer, so they are not required in the repo.

The .gitignore file is placed in the C:\Windows\System32\config\systemprofile\AppData\Local\Jenkins.jenkins path (as the Jenkins Home environment variable), and the folders to be ignored are in the C:\Windows\System32\config\systemprofile\AppData\Local\Jenkins.jenkins\workspace\SFDC Deployment\SF Prod (GH) folder, and they are called .sf and .sfdx

I tried several ways to include the folders in the .gitignore file but none of them is working:

**/SF Prod (GH)/.sfdx/
**/SF Prod (GH)/.sf/

I also tried to move the .gitignore file to the C:\Windows\System32\config\systemprofile\AppData\Local\Jenkins.jenkins\workspace folder with the same results.

What I´m doing wrong?
Is the .gitignore file location wrong or it is a .gitignore syntax issue?

Thanks in advance

Are the things you put in the .gitignore already part of the repository? If yes then the .gitignore has no effect during a git checkout

Thanks for your answer.

No, they don´t. Those folders/files are not part of the repository. They are added when the Jenkins jobs are executed.
I removed them manually from the repo, but they back to it again after the new execution.

Javier Carvajal

Then your build process must be adding them.
A .gitignore will just hide things from git status and avoid that you accidently add them with git add .. It will not prevent that you create those files/folders.

1 Like

I don´t understand what you are saying.
I´m using the .gitignore file locally in the same way and with the same content, and both folders´ changes are ignored and are not included in the list of changes to be tracked in the repo.
But in the Jenkins server, I´m unable to skip those server folders in git.

Have you checked in the .gitignore to your repo?
In the jenkins server those directories should not exist at all because you said they are not checked in to git. So when you start from a clean directory how should they get there other than your build process? And are you doing things like git add in your build process?

Those directories are created automatically, as the Jenkins job is connecting to SF orgs, and those directories contain the config files to connect to each org (config.json file with the alias per each org,…).
They are automatically generated when the connection is established and they contain different parameter values per each developer. Because of that, they should not be included in the repo.
As said, the .gitignore file is working fine per developers, so they don´t include those folders in the repo when they commit, but the Jenkins server is including them in the repo every time the jobs are executed, causing developers to receive those folders that have changed in the repo when they should not be there.

Repeating my question: Do you have the .gitignore checked in to your repo?

No, the .gitignore file doesn´t exist in the repo. It only exists locally, the same as it is on my laptop where it is working fine and no changes on those folders are being included in the repo.

Then I suggest to add the .gitignore to your repo. Then you don’t need to care if you move the build to a different machine, people that start using the repo for the first time don’t need any manual things to ensure they have a proper .gitignore somewhere else.

Markus, thank you so much for your help.

Now it is working as expected.
Due to, in my local laptop, the .gitignore file is located one level up of the repository parent folder I didn´t know that if it would be included in the repo it would also work.

Javier Carvajal