appspec.yml文件解析

appspec.yml是CodeDeploy服务中定义操作和文件映射的关键文件,它包括version、os、files、permissions和hooks等部分。version指定API版本,os指明操作系统。files部分定义源文件和目标路径,permissions设置文件权限。hooks段则涵盖了部署过程中的各个阶段,如ApplicationStop、BeforeInstall等,允许自定义操作。hook的location指定脚本路径,timeout设置超时时间,runas定义执行身份。appspec.yml的格式严格,包括空格数量的精确要求。

appspec.yml是YAML格式、用于定于CodeDeploy服务在整个阶段所做的操作和文件拷贝路径和权限等。首先,这个文档名称必须是appspec.yml,而且文档中的空格个数也有严格的要求,文章最后面会讲到。
appspec.yml文档结构:

version: 0.0
os: operating-system-name
files:
  source-destination-files-mappings
permissions:
  permissions-specifications
hooks:
  deployment-lifecycle-event-mappings

version这里,类似于aws api的版本号,目前只能写0.0
os这里可接受的选项是linux和windows,全小写
files段,定于文件映射关系,例如下面这段

files:
   - source: Config/config.txt
     destination: /webapps/Config
   - source: source
     destination: /webapps/myApp

source文件路径是是相对于本版包的相对路径,如果是/,表示本版包里的全部文件和目录
destination这里是被部署服务器的完整路径(绝对路径)

permission段:用于定义和描述被拷贝到目标服务器上的文件拷贝后的权限
例如下面这个例子

permissions:
   - object: /home/webapp/tomcat/webapps/cms-front
     pattern: "**"
     except: /home/webapp/tomcat/webapps/cms-front/version.ini
     owner: webapp
     g
#!/bin/bash # Copyright (c) Huawei Technologies Co., Ltd. 2010-2022. All rights reserved. set -ex #获取jinkins的$buildNumber,获取时间戳,获取build随机数 if [ -e /proc/sys/kernel/random/uuid ] && [ -r /proc/sys/kernel/random/uuid ];then build="$(cat /proc/sys/kernel/random/uuid| cksum | cut -f1 -d" ")" else build=${RANDOM} fi datetime="$(date +%Y%m%d%H%M%S)" BUILD_NUMBER="${datetime}.${build}" #微服务名称 SERVICE_NAME="" #包所在的项目路径 PACKAGE_PATH="" #包名称 PACKAGE_NAME="" #rm -rf /usr1/maven/.m2/repository/com/huawei/mes/ldmbaseservice/mlmldmservice-SNAPSHOT/ #rm -rf /usr1/maven/.m2/repository/com/huawei/mes/ldmcoreservice/mlmldmservice-SNAPSHOT/ echo "Release is ${ENV_IS_RELEASE}" #判断当前构建是否为版本构建,以及定义构建变量(包版本,包服务名称,包编译存放路径,包类型,包编译名称,包打包名称) if [ "${ENV_IS_RELEASE}"x = "false"x ];then SERVICE_VERSION='1.0.0-SNAPSHOT' #版本号+时间戳+build随机数写入buildInfo.properties echo "buildVersion=${SERVICE_VERSION}.$BUILD_NUMBER">buildInfo.properties #sed -i 's/VERSION/'${SERVICE_VERSION}.${BUILD_NUMBER}'/g' appspec.yml #压缩包名称 PACKAGE_TAR_PATH="${SERVICE_NAME}_${SERVICE_VERSION}.${BUILD_NUMBER}" #执行工程编译 workdir=$(cd $(dirname $0); pwd) cd $workdir #maven打包命令 if [ "${env}"x = "dev"x ];then mvn clean install package -Dmaven.test.skip=true -Pdev -U -gs settings.xml -s settings.xml elif [ "${env}"x = "sit"x ];then mvn clean install package -Dmaven.test.skip=true -P!dev,sit -U -gs settings.xml -s settings.xml elif [ "${env}"x = "uat"x ];then mvn clean install package -Dmaven.test.skip=true -P!dev,uat -U -gs settings.xml -s settings.xml else mvn clean install package -Dmaven.test.skip=true -Pdev -U -gs settings.xml -s settings.xml fi mkdir package cp target/*.gz package elif [ "${ENV_IS_RELEASE}"x = "true"x ];then SERVICE_VERSION=${ENV_RELEASE_VERSION} #版本号+时间戳+build随机数写入buildInfo.properties echo "buildVersion=${SERVICE_VERSION}">buildInfo.properties #sed -i 's/VERSION/'${SERVICE_VERSION}'/g' appspec.yml #压缩包名称 PACKAGE_TAR_PATH="${SERVICE_NAME}_${SERVICE_VERSION}" #执行工程编译 workdir=$(cd $(dirname $0); pwd) cd $workdir #Maven打包命令 mvn clean install package -Dmaven.test.skip=true -P!dev,prod -U -gs settings.xml -s settings.xml mkdir package cp target/*.gz package fi
最新发布
11-08
#!/bin/bash set -ex #获取jinkins的$buildNumber,获取时间戳,获取build随机数 if [ -z ${buildNumber} ];then if [ -e /proc/sys/kernel/random/uuid ] && [ -r /proc/sys/kernel/random/uuid ];then build=`cat /proc/sys/kernel/random/uuid| cksum | cut -f1 -d" "` else build=${RANDOM} fi datetime=`date +%Y%m%d%H%M%S` buildNumber="${datetime}.${build}" else buildNumber="${buildNumber}" fi # 解决升级 node 18 报错问题:rror: error:0308010C:digital envelope routines::unsupported export NODE_OPTIONS=--openssl-legacy-provider #微服务名称 SERVICE_NAME="" #包所在的项目路径 PACKAGE_PATH="" #包名称 PACKAGE_NAME="" echo "Release is ${isRelease}" #判断当前构建是否为版本构建,以及定义构建变量(包版本,包服务名称,包编译存放路径,包类型,包编译名称,包打包名称) if [ "${isRelease}"x = "false"x ];then SERVICE_VERSION='1.0.0-SNAPSHOT' #版本号+时间戳+build随机数写入buildInfo.properties echo "buildVersion=${SERVICE_VERSION}.$buildNumber">buildInfo.properties #sed -i 's/VERSION/'${SERVICE_VERSION}.${buildNumber}'/g' appspec.yml #压缩包名称 PACKAGE_TAR_PATH="${SERVICE_NAME}_${SERVICE_VERSION}.${buildNumber}" elif [ "${isRelease}"x = "true"x ];then SERVICE_VERSION=${releaseVersion} #版本号+时间戳+build随机数写入buildInfo.properties echo "buildVersion=${SERVICE_VERSION}">buildInfo.properties #sed -i 's/VERSION/'${SERVICE_VERSION}'/g' appspec.yml #压缩包名称 PACKAGE_TAR_PATH="${SERVICE_NAME}_${SERVICE_VERSION}" fi #执行工程编译 workdir=$(cd $(dirname $0); pwd) cd $workdir #当前sh脚本在.cloudbuild目录,需要退到上一层目录 cd .. npm config set "registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/npm-central-repo/ npm config set "@ffe:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/ npm config set "@aurora:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/ npm config set "@avenueui:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/ npm config set "@originjs:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/ npm config set "@starling-devkit:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/ npm config set "@aurora-uikit:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/ npm config set "@luban:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/ npm config set "@starling:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/ npm config set "@aurora-devkit:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/ npm config set "@aurora-one:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/ npm config set "@turboui:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/ npm config set "@linkjs:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/ npm config set "@phoenix:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/ npm config set "@publicsaas:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/ npm config set "@cloud:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/ npm config set "@babel:registry" https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/npm-central-repo/ npm config set "strict-ssl" false pnpm install npm run dynamic:build -- --env ${env:=prod} --single-project-package ${single:=false} --scope ${scope:=false} --app ${app:=false} --template-prefix dp_ cd ./dist ls 以上是我的build脚本,流水线报错如下,请问原因是什么?怎么调整? [2025/08/30 10:13:36.810 GMT+08:00] [INFO] [BUILD:build_execute] : launched task [2025/08/30 10:13:36.812 GMT+08:00] [INFO] [BUILD:build_execute] : start to get result. [2025/08/30 10:13:37.318 GMT+08:00] + sh SIT/.cloudbuild/build.sh [2025/08/30 10:13:37.318 GMT+08:00] SIT/.cloudbuild/build.sh: line 2: set: - : invalid option [2025/08/30 10:13:37.318 GMT+08:00] set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] [2025/08/30 10:13:37.338 GMT+08:00] [ERROR] [BUILD:build_execute] : script returned exit code 2, exitMessage: command run failed [2025/08/30 10:13:37.894 GMT+08:00] [ERROR] [BUILD:build_execute] : Error message: 执行脚本sh SIT/.cloudbuild/build.sh...失败:script returned exit code 2, exitMessage: command run failed [2025/08/30 10:13:38.080 GMT+08:00] [ERROR] [BUILD:build_execute] : Failed to complete this step
08-31
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值