Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom host entries to jenkins slave agent pod

I have deployed current version https://github.com/helm/charts/tree/master/stable/jenkins in my cluser .

Question is - How do I add values to /etc/hosts for slave agent.

For Master I am able to achieve this using

- hostAliases 

Which is working fine.

But not able to figure it out for slave agent. (Currently I am using -

image: "jenkins/jnlp-slave"
  tag: "3.27-1"

The problem is slave agent is not able to connect to github and artifactory. I Need a way to updates values in /etc/hosts or do we have any other approach?

like image 613
pythonhmmm Avatar asked Sep 08 '25 16:09

pythonhmmm


1 Answers

Try specify custom yaml in podTemplate() https://www.jenkins.io/doc/pipeline/steps/kubernetes/#podtemplate-define-a-podtemplate-to-use-in-the-kubernetes-plugin like this:

podTemplate(label: nodeLabel,
            yaml: """
spec:
  hostAliases:
  - ip: "your_ip_address"
    hostnames:
    - "my.hostname.com"
    - "another.host.com"
            """,
            containers: ...,
            volumes: ...) { }

It works well for me.

like image 171
Pavel Kovalev Avatar answered Sep 10 '25 05:09

Pavel Kovalev