-bash: ./deploy.sh: /bin/bash^M: bad interpreter: No such file or directory

博客讲述Jenkins发布失败,报错显示远程服务器deploy.sh执行失败,检查权限无问题,手动执行报错提示脚本是Windows回车符结尾。解决办法是使用sed -i -e ‘s/\r$//’ deploy.sh 处理脚本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文章目录

场景

jenkins 发布失败, 报错ERROR: Exception when publishing, exception message [Exec exit status not zero. Status [126]], 这说明远程服务器的deploy.sh执行失败, 首先检查权限,没有发现问题,然后手动执行一遍又报错"-bash: ./deploy.sh: /bin/bash^M: bad interpreter: No such file or directory", 这个意味着脚本是windows回车符结尾

[JENKINS] Archiving /home/vagrant/.jenkins/workspace/jenkinsDemo/target/jenkinsDemo-1.0-SNAPSHOT.jar to com.carsonlius/jenkinsDemo/1.0-SNAPSHOT/jenkinsDemo-1.0-SNAPSHOT.jar
channel stopped
SSH: Connecting from host [ubuntu-xenial]
SSH: Connecting with configuration [107.173.111.224 自己] ...
SSH: EXEC: completed after 604 ms
SSH: Disconnecting configuration [107.173.111.224 自己] ...
ERROR: Exception when publishing, exception message [Exec exit status not zero. Status [126]]
Build step 'Send build artifacts over SSH' changed build result to UNSTABLE

解决

sed -i -e ‘s/\r$//’ deploy.sh

[root@control ansible]# ansible-playbook -i inventory k8s-deploy.yml PLAY [Deploy Kubernetes Cluster on openEuler] ************************************************************************* TASK [Gathering Facts] ************************************************************************************************ [WARNING]: Platform linux on host control is using the discovered Python interpreter at /usr/bin/python3, but future installation of another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. ok: [control] [WARNING]: Platform linux on host node02 is using the discovered Python interpreter at /usr/bin/python3, but future installation of another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. ok: [node02] [WARNING]: Platform linux on host node01 is using the discovered Python interpreter at /usr/bin/python3, but future installation of another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. ok: [node01] TASK [Install required packages] ************************************************************************************** fatal: [node02]: FAILED! => {"changed": false, "msg": "Failed to download metadata for repo 'docker-ce-stable': Cannot prepare internal mirrorlist: Cannot resolve path for: \"releasever/$\"", "rc": 1, "results": []} fatal: [control]: FAILED! => {"changed": false, "msg": "Failed to download metadata for repo 'docker-ce-stable': Cannot prepare internal mirrorlist: Cannot resolve path for: \"releasever/$\"", "rc": 1, "results": []} fatal: [node01]: FAILED! => {"changed": false, "msg": "Failed to download metadata for repo 'docker-ce-stable': Cannot prepare internal mirrorlist: Cannot resolve path for: \"releasever/$\"", "rc": 1, "results": []} PLAY RECAP ************************************************************************************************************ control : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 node01 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 node02 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 [root@control ansible]# cat k8s-deploy.yml --- - name: Deploy Kubernetes Cluster on openEuler hosts: k8s_cluster become: yes vars: kubernetes_version: "1.28.0" containerd_version: "1.6.21" tasks: - name: Install required packages dnf: name: - curl - wget - vim - socat - conntrack-tools - ipvsadm - docker state: present - name: Start and enable Docker service systemd: name: docker enabled: yes state: started - name: Disable Swap command: swapoff -a ignore_errors: yes - name: Remove Swap from /etc/fstab replace: path: /etc/fstab regexp: '^([^#].*?\sswap\s+sw\s+.*)$' replace: '# \1' - name: Load Kernel Modules modprobe: name: "{{ item }}" state: present loop: - br_netfilter - overlay - name: Install containerd dnf: name: "containerd.io-{{ containerd_version }}.el7.x86_64" state: present - name: Configure containerd copy: dest: /etc/containerd/config.toml content: | version = 2 [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc] runtime_type = "io.containerd.runc.v2" [plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"] endpoint = ["https://registry-1.docker.io"] - name: Persist Kernel Modules copy: dest: /etc/modules-load.d/k8s.conf content: | br_netfilter overlay - name: Configure Sysctl copy: dest: /etc/sysctl.d/k8s.conf content: | net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1 notify: Reload Sysctl - name: Add Kubernetes YUM Repo copy: dest: /etc/yum.repos.d/kubernetes.repo content: | [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg - name: Install Kubernetes components dnf: name: - kubelet-{{ kubernetes_version }} - kubeadm-{{ kubernetes_version }} - kubectl-{{ kubernetes_version }} state: present disable_gpg_check: yes - name: Enable kubelet systemd: name: kubelet state: started enabled: yes - name: Initialize Kubernetes Master (Control Node Only) command: kubeadm init --pod-network-cidr=192.168.0.0/16 when: inventory_hostname == "control" register: kubeadm_init - name: Save kubeadm join Command (Control Node Only) copy: dest: /root/kubeadm-join.sh content: | #!/bin/bash {{ kubeadm_init.stdout_lines[-1] }} mode: '0700' when: inventory_hostname == "control" - name: Get kubeadm join Command from Control Node (Worker Nodes Only) slurp: src: /root/kubeadm-join.sh register: kubeadm_join delegate_to: control when: inventory_hostname != "control" - name: Execute kubeadm join on Worker Nodes command: "{{ kubeadm_join.content | b64decode }}" when: inventory_hostname != "control" handlers: - name: Reload Sysctl command: sysctl --system [root@control ansible]#
最新发布
07-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值