How to pass Git credentials in a Kustomize build command?

2.1k views Asked by At

I have a kustomization.yaml file that uses a private repository as a resource:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - https://gitlab.com/my-user/k8s-base-cfg.git
patchesStrategicMerge:
  - app-patch.yaml

I want to automate this on a Jenkins Pipeline. I don't know how to pass Git credentials to the kustomize build command. Is there any option to do that?

Thank you

2

There are 2 answers

0
coderanger On BEST ANSWER

You can't, you would set up the credentials in git before starting Kustomize. In this case probably something very simple like git config --global user.password "your password" but look up the credentials.helper setting for more complex options, either from a local file or a tool that reads from some backing store directly.

0
Chris Jones On

@coderanger's answer is correct, but doesn't work for me. I use this:

git config --global credential.helper store
echo "https://$GITUSER:[email protected]" >> "${HOME}/.git-credentials"

If you're using GitHub, $GITUSER = git (it's ignored) and $PASSWORD = a personal access token.