gangkui2008
gangkui2008

Reputation: 157

jenkins pipeline failed: Exec Failure: HTTP:401. Message:Unauthorized

I ran jenkins in k8s cluster, and I installed the kubernetes plugin in the jenkins.

The pipeline failed with below jenkins log:

2025-01-14 06:48:38.371+0000 [id=2218]  INFO    o.internal.platform.Platform#log: ALPN callback dropped: HTTP/2 is disabled. Is alpn-boot on the boot class path?
2025-01-14 06:48:38.439+0000 [id=2174]  INFO    o.c.j.p.k.p.ContainerExecDecorator$1#doLaunch: Created process inside pod: [maven-r266l], container: [maven][90 ms]
2025-01-14 06:48:38.766+0000 [id=2218]  INFO    o.internal.platform.Platform#log: ALPN callback dropped: HTTP/2 is disabled. Is alpn-boot on the boot class path?
2025-01-14 06:48:38.793+0000 [id=2218]  SEVERE  i.f.k.c.d.i.ExecWebSocketListener#onFailure: Exec Failure: HTTP:401. Message:Unauthorized
java.net.ProtocolException: Expected HTTP 101 response but was '401 Unauthorized'
        at okhttp3.internal.ws.RealWebSocket.checkResponse(RealWebSocket.java:229)
        at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:196)
        at okhttp3.RealCall$AsyncCall.execute(RealCall.java:203)
        at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
2025-01-14 06:48:39.153+0000 [id=2174]  INFO    o.c.j.p.k.KubernetesSlave#_terminate: Terminating Kubernetes instance for agent maven-r266l
2025-01-14 06:48:39.177+0000 [id=2174]  INFO    o.internal.platform.Platform#log: ALPN callback dropped: HTTP/2 is disabled. Is alpn-boot on the boot class path?
2025-01-14 06:48:39.335+0000 [id=2256]  INFO    o.j.p.workflow.job.WorkflowRun#finish: appjkzql/pm-mom/ks-hz #73 completed: FAILURE
2025-01-14 06:48:39.445+0000 [id=2174]  INFO    o.c.j.p.k.KubernetesSlave#deleteSlavePod: Terminated Kubernetes instance for agent kubesphere-devops-worker/maven-r266l
2025-01-14 06:48:39.446+0000 [id=2174]  INFO    o.c.j.p.k.KubernetesSlave#_terminate: Disconnected computer maven-r266l
Terminated Kubernetes instance for agent kubesphere-devops-worker/maven-r266l
Disconnected computer maven-r266l
2025-01-14 06:48:39.449+0000 [id=2256]  INFO    j.s.DefaultJnlpSlaveReceiver#channelClosed: Computer.threadPoolForRemoting [#230] for maven-r266l terminated: java.nio.channels.ClosedChannelException
2025-01-14 06:48:39.451+0000 [id=2217]  INFO    hudson.remoting.Request$2#run: Failed to send back a reply to the request hudson.remoting.Request$2@74b67b7b: hudson.remoting.ChannelClosedException: Channel "hudson.remoting.Channel@3c9dbe07:JNLP4-connect connection from 10.233.70.92/10.233.70.92:55624": channel is already closed

the jenkinsfile is very simple, the core piece:

    stages {
        stage('docker-login') {
      
            steps {
                container('maven') {
                  echo 'hello'
                  sh 'docker login $REGISTRY -u xxx -p xxx'
                }

            }
        }
    }

the weird thing is, I ran the pipeline many times, most times it failed (at above stage), sometimes it succeeded.

The 401 status code seems indicate something like token used by jenkins is not correct, but I don't know which one.

Anyone knows how to resolve this? thanks very much!

Upvotes: 0

Views: 30

Answers (1)

gangkui2008
gangkui2008

Reputation: 157

Turned out it's due to one master of 5 in the k8s has expired kube-apiserver certificates.

1/5 possibility the jenkins connected to this master thus get 401 Unauthorized.

Ran kubeadm certs renew all then restarted the k8s components, everything went okay now.

Upvotes: 0

Related Questions