在jenkins中实用shell

Posted wzj_what_why_how

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在jenkins中实用shell相关的知识,希望对你有一定的参考价值。

在jenkiins中配置shell脚本,对需要打包的项目做一下特定的配置和修改

代码:

    echo "$android_HOME" >> local.properties
    if [[ $DEBUG_ENV == true ]] ; then
      sed -i '' 's/public final static boolean sIsDebug = false;/public final static boolean sIsDebug = true;/g' base/src/main/java/com/base/api/Constants.java
      echo "build debug env"
    else
      sed -i '' 's/public final static boolean sIsDebug = true;/public final static boolean sIsDebug = false;/g' base/src/main/java/com/base/api/Constants.java 
      echo "build release env"
    fi
    
    if [[ $ENABLE_VIN_CHECK == true ]] ; then
      sed -i '' 's/public final static boolean ENABLE_CHECK_VIN = false;/public final static boolean ENABLE_CHECK_VIN = true;/g' base/src/main/java/com/base/api/Constants.java
    else
      sed -i '' 's/public final static boolean ENABLE_CHECK_VIN = true;/public final static boolean ENABLE_CHECK_VIN = false;/g' base/src/main/java/com/base/api/Constants.java 
    fi

代码:

    cp -rf ./"agconnect-services_beta.json" ./app/"agconnect-services.json"
    
    if [[ $LOCAL_LUA == true ]] ; then
      sed -i '' 's/private static final boolean IS_LOCAL_TEST = false;/private static final boolean IS_LOCAL_TEST = true;/g' core/src/main/java/com/core/lua/LuaManager.java
      echo "build debug env"
    else
      sed -i '' 's/private static final boolean IS_LOCAL_TEST = true;/private static final boolean IS_LOCAL_TEST = false;/g' core/src/main/java/com/core/lua/LuaManager.java 
      echo "build release env"
    fi

代码:

version=$BUILD_DISPLAY_NAME
	jobname="Beta版本"
	changetitle=$CHANGE_TITLE
	svnrevision=$SVN_REVISION
	temp_product_type=$productType
	new_filename=cartect_pro_$productType_$SVN_REVISION
	
	if [[ $DEBUG_ENV == true ]] ; then
	    jobname="$jobname_测试环境"
	    new_filename="$new_filename_TestServer"
	    plat_id=10
	else
	    jobname="$jobname_正式环境"
	    new_filename="$new_filename_OnlineServer"
	    plat_id=12
	fi
	
	if [[ $productType == "assemblebetaRelease" ]] ; then
	    jobname="$jobname_Release"
	    temp_product_type="release"
	    plat_id=$[$plat_id+1]
	else
	    jobname="$jobname_Debug"
	    temp_product_type="debug"
	fi
	
	mv app/build/outputs/apk/beta/$temp_product_type/app-beta-$temp_product_type.apk app/build/outputs/apk/beta/$temp_product_type/a.apk

其他:

Linux 命令大全

另一篇shell基础

以上是关于在jenkins中实用shell的主要内容,如果未能解决你的问题,请参考以下文章

利用jenkins自由风格用shell脚本进行所有项目发版(java项目)

jenkins执行shell脚本执行docker操作权限问题?

记录Jenkins在m1上使用的坑

jenkins中shell脚本编写的两个注意点

Jenkins自动部署Shell脚本

构建步骤“执行 shell”在 Jenkins CI 上将构建标记为失败,没有任何错误