我正在设置Jenkins管道来部署PHP应用程序。该应用程序正在使用composer,因此我在脚本中运行composer install -o
以确保所有依赖项都存在。测试设置还可以确保生成vendor/autoload.php
(位于phpunit.xml
引导程序配置中)
我的脚本基于https://modess.io/jenkins-php/和http://jenkins-php.org/
我的问题是不包括vendor
文件夹,也不包括生成的config.inc.php
。
Jenkins日志显示我的部署行sh "cp -rp ${SOURCE_DIR}/* ${DEPLOY_DIR}"
被扩展为cp -rp src/globals.template.inc.php src/index.php src/phpinfo.php /usr/nasShare/htdocs/sometest
,其中不包括上述文件。 (实际上,这些是SCM的src目录中的唯一文件。在jenkins服务器上的工作目录中,这些文件已生成...)
#!groovy
pipeline {
agent any
environment {
SOURCE_DIR="src"
TEMPLATE_FILE="globals.template.inc.php"
CONFIG_FILE="globals.inc.php"
}
stages {
stage ('Testing'){
steps {
echo "Running ant clean"
sh 'ant clean'
echo "running composer"
sh "composer install -o -d ${SOURCE_DIR}"
echo ""
sh 'ant quick-build'
}
}
stage ('Staging'){
steps {
echo "Building config file"
script {
def inptext = readFile file: "${SOURCE_DIR}/${TEMPLATE_FILE}"
inptext = inptext.replaceAll(~/¤GIT_BRANCH¤/, "${GIT_BRANCH_NAME}")
inptext = inptext.replaceAll(~/¤GIT_COMMIT¤/, "${sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()}")
inptext = inptext.replaceAll(~/¤GIT_TAG¤/, "${sh(returnStdout: true, script: "git -C . describe --tags").trim()}")
writeFile file: "${SOURCE_DIR}/${CONFIG_FILE}", text: inptext
}
}
}
stage ('Remote Deploy'){
agent any
when{
//https://stackoverflow.com/a/44231270/1725871
environment name: 'DEPLOY_TYPE', value: 'remote'
}
steps {
echo "Deploying via SSH on ${SSH_SERVER_NAME}:${DEPLOY_DIR}"
//TODO: rename backup file
sh "ssh ${SSH_USERNAME}@${SSH_SERVER_NAME} tar -cvpzf BACKUP_FNAME ${DEPLOY_DIR}/* "
sh "ssh ${SSH_USERNAME}@${SSH_SERVER_NAME} rm -R ${DEPLOY_DIR}/*"
sh "scp -rp ${SOURCE_DIR}/* ${SSH_USERNAME}@${SSH_SERVER_NAME}:${DEPLOY_DIR}"
//TODO: delete backup on success
}
}
stage ('Local Deploy'){
agent any
when{
environment name: 'DEPLOY_TYPE', value: 'local'
}
steps {
echo "Deploying to ${DEPLOY_DIR} "
//TODO: backup existing files
sh "rm -R ${DEPLOY_DIR}/*"
sh "cp -rp ${SOURCE_DIR}/* ${DEPLOY_DIR}"
}
}
}
}
答案 0 :(得分:0)
我发现了自己的错误。将${WORKSPACE}/
添加到我的SOURCE_DIR
变量即可解决该问题。现在所有预期的文件都将被复制。
environment {
SOURCE_DIR="${WORKSPACE}/src"
TEMPLATE_FILE="globals.template.inc.php"
CONFIG_FILE="globals.inc.php"
}