Skip to content

Instantly share code, notes, and snippets.

@cloudyyoung
Created January 7, 2021 12:42
Show Gist options
  • Select an option

  • Save cloudyyoung/cec1f5849bdb25eb82063b4da3a09af2 to your computer and use it in GitHub Desktop.

Select an option

Save cloudyyoung/cec1f5849bdb25eb82063b4da3a09af2 to your computer and use it in GitHub Desktop.
Jenkinsfile - Build PHP by Composer and deploy to server by Publish Over SSH
pipeline {
agent any
environment {
DEPLOY_DIR = "/home/wwwroot/default/charity-jenkins"
DEPLOY_NAME = "deploy.tar.gz"
}
stages {
stage('Build') {
steps {
sh 'php --ini'
sh 'composer install --no-dev'
}
}
stage('Compress') {
steps {
sleep 4
sh "tar -cvz --warning=no-file-changed --exclude=\'.git\' --exclude=${DEPLOY_NAME} -f ${DEPLOY_NAME} ."
}
}
stage('Deploy') {
steps {
sshPublisher(
continueOnError: false,
failOnError: true,
publishers: [
sshPublisherDesc(
configName: "Charity Server",
verbose: true,
transfers: [
sshTransfer(
sourceFiles: "deploy.tar.gz",
removePrefix: "",
remoteDirectory: "${DEPLOY_DIR}",
execCommand: """
cd ${DEPLOY_DIR}
tar -xzvf deploy.tar.gz
""",
)
]
)
]
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment