Kubectl on jenkinsfile

Hi everyone,

i’m able to execute kubectl over command line in linux, but i get error bellow when running the same command in jenkinsfile. Can anybody help me, please?

Error: Unable to initialize DigitalOcean API client: access token is required. (hint: run ‘doctl auth init’)


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi @bobbyiliev

Thank you for answering me.

I solved it changing the approaching by using kubernetes plugin.


Hi there @carlosbenicio79,

It is quite possible that your Jenkins service is running as a different user so it does not have access to the Kubernetes config file of your SSH user.

What you could do is add an extra step in your Jenkinsfile to first authenticate with doctl, it would look something like this:

doctl auth init --access-token "your_digitalocean_token"

I would recommend adding your DigitalOcean access token as a Jenkins secret rather than hardcoding it in your Jenkinsfile.

And then add another step to save the Kubernetes config:

doctl kubernetes cluster kubeconfig save use_your_cluster_name

Hope that this helps! Regards, Bobby