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

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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