1 Star 1 Fork 0

kern-417/project-bluej51-cms

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Jenkinsfile 3.62 KB
一键复制 编辑 原始数据 按行查看 历史
kern-417 提交于 2023-07-30 19:04 . init
pipeline {
agent any
stages {
stage('检出') {
steps {
checkout([$class: 'GitSCM',
branches: [[name: GIT_BUILD_REF]],
userRemoteConfigs: [[
url: GIT_REPO_URL,
credentialsId: CREDENTIALS_ID
]]])
}
}
stage('依赖漏洞扫描') {
steps {
npmAuditInDir(directory: '/', collectResult: true)
}
}
stage('安装依赖') {
steps {
sh 'npm install'
}
}
stage('构建镜像并推送到 CODING Docker 制品库') {
steps {
sh "docker build -t ${CODING_DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION} -f ${DOCKERFILE_PATH} ${DOCKER_BUILD_CONTEXT}"
useCustomStepPlugin(key: 'SYSTEM:artifact_docker_push', version: 'latest', params: [image:"${CODING_DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}",repo:"${DOCKER_REPO_NAME}",properties:'[]'])
}
}
stage('部署到远端服务') {
steps {
script {
def remoteConfig = [:]
remoteConfig.name = "my-remote-server"
remoteConfig.host = "${REMOTE_HOST}"
remoteConfig.port = "${REMOTE_SSH_PORT}".toInteger()
remoteConfig.allowAnyHosts = true
withCredentials([
sshUserPrivateKey(
credentialsId: "${REMOTE_CRED}",
keyFileVariable: "privateKeyFilePath"
),
usernamePassword(
credentialsId: "${CODING_ARTIFACTS_CREDENTIALS_ID}",
usernameVariable: 'CODING_DOCKER_REG_USERNAME',
passwordVariable: 'CODING_DOCKER_REG_PASSWORD'
)
]) {
// SSH 登录用户名
remoteConfig.user = "${REMOTE_USER_NAME}"
// SSH 私钥文件地址
remoteConfig.identityFile = privateKeyFilePath
// 请确保远端环境中有 Docker 环境
sshCommand(
remote: remoteConfig,
command: "docker login -u ${CODING_DOCKER_REG_USERNAME} -p ${CODING_DOCKER_REG_PASSWORD} ${CODING_DOCKER_REG_HOST}",
sudo: true,
)
// 移除已有的容器
sshCommand(
remote: remoteConfig,
command: "docker rm -f ${DOCKER_IMAGE_NAME} | true",
sudo: true,
)
// DOCKER_IMAGE_VERSION 中涉及到 GIT_LOCAL_BRANCH / GIT_TAG / GIT_COMMIT 的环境变量的使用
// 需要在本地完成拼接后,再传入到远端服务器中使用
DOCKER_IMAGE_URL = sh(
script: "echo ${CODING_DOCKER_REG_HOST}/${CODING_DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}",
returnStdout: true
)
sshCommand(
remote: remoteConfig,
command: "echo \$(sh /generatePort.sh)",
sudo: true
)
sshCommand(
remote: remoteConfig,
command: "command=\"docker run -d -p \$port:\${CODING_PROJECT_PORT} --name ${DOCKER_IMAGE_NAME} ${DOCKER_IMAGE_URL}\"",
)
sshCommand(
remote: remoteConfig,
command: "eval $command",
sudo: true,
)
sshCommand(
remote: remoteConfig,
command: "export CODING_DOCKER_PORT=\${port}",
sudo: true,
)
echo "部署成功,请到 http://${REMOTE_HOST}:${CODING_DOCKER_PORT} 预览效果"
}
}
}
}
}
environment {
CODING_DOCKER_REG_HOST = "${CCI_CURRENT_TEAM}-docker.pkg.${CCI_CURRENT_DOMAIN}"
CODING_DOCKER_IMAGE_NAME = "${PROJECT_NAME.toLowerCase()}/${DOCKER_REPO_NAME}/${DOCKER_IMAGE_NAME}"
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kern-417/project-bluej51-cms.git
[email protected]:kern-417/project-bluej51-cms.git
kern-417
project-bluej51-cms
project-bluej51-cms
master

搜索帮助