zoukankan      html  css  js  c++  java
  • jenkins 执行shell编译go 代码报错:build cache is required, but could not be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME are defined

    jenkins执行shell编译go代码时,全部报错:

         build cache is required, but could not be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME are defined

    执行go env 没用信息显示,也是上面的报错。

    但是,在jenkins机器上执行shell编译go代码和执行go env 都可以正常运行

    只要jenkins调用就不生效了

    原因:jenkins 执行shell有时候不能全部读取到机器上的环境变量。

    解决:

    在jenkins 机器上执行 go env > go_env  将go env用到的环境变量写入到文件go_env (这个文件名可以随便定义)

    然后再执行 sed -i ‘s/^/export  /'  go_env 在每一行的行首加入export 

    然后备份下你自己的~/.bashrc :  cp ~/.bashrc bashrc_bak  防止待会改坏了

    然后将go_env追加到~/.bashrc中: cat  go_env >> ~/.bashrc

    最后执行source ~/.bashrc  让环境变量生效

    如果不放心的话 在jenkins要执行的脚本中也加上 source ~/.bashrc  这一句。

    另外,在尝试上面的步骤之前我还在/etc/profile中加入了GOROOT环境变量,不知道这个步骤有没有用到,如果你在操作了上面的步骤后还是失败的,可以尝试加一下,并source下这个文件

       GOROOT=/usr/local/go  #GOROOT是你的go的安装路径

       export PATH=$GOROOT/bin:$PATH



  • 相关阅读:
    django 如何重用app
    vim常用命令
    linux find grep
    linux su su-的区别
    linux定时任务crontab
    linux shell的单行多行注释
    python字符串的截取,查找
    gdb调试
    python字符转化
    python读写文件
  • 原文地址:https://www.cnblogs.com/zndxall/p/12896334.html
Copyright © 2011-2022 走看看