serverless.yml
configuration file used for execution in Serverless Framework CLI.- name: serverless scf deployuses: woodyyan/tencent-serverless-action@main
# When the code is pushed to the `main` branch, the current workflow will be executed# For more information on configuration, visit https://docs.github.com/cn/actions/getting-started-with-github-actions.name: deploy serverless scfon: # Configuration of the event and branch listened onpush:branches:- mainjobs:deploy:name: deploy serverless scfruns-on: ubuntu-lateststeps:- name: clone local repositoryuses: actions/checkout@v2- name: deploy serverlessuses: woodyyan/tencent-serverless-action@mainenv: # Environment variableSTAGE: dev # Your deployment environmentSERVERLESS_PLATFORM_VENDOR: tencent # The serverless platform is `aws` by default outside the Chinese mainland. Here, it is set to `tencent`TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }} # `secret ID` of your Tencent Cloud account, which needs to be configured in `Settings-Secrets`TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }} # `secret key` of your Tencent Cloud account, which needs to be configured in `Settings-Secrets`
name: deploy serverless scfon: # Configuration of the event and branch listened onpush:branches:- mainjobs:build-and-deploy:runs-on: ubuntu-latestpermissions:contents: readpackages: writesteps:- uses: actions/checkout@v2- name: Set up JDK 11uses: actions/setup-java@v2with:java-version: '11'distribution: 'temurin'server-id: github # Value of the distributionManagement/repository/id field of the pom.xmlsettings-path: ${{ github.workspace }} # location for the settings.xml file- name: Build with Gradle # Use this for a Gradle projectuses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7with:arguments: build- name: Build with Maven # Use this for a Maven projectrun: mvn -B package --file pom.xml- name: Create zip folder # This step is used to store JAR and `scf_bootstrap` files for HTTP-triggered Java functions. You only need to specify the `Jar` directory in `Serverless.yml` for event-triggered Java functions.run: mkdir zip- name: move jar and scf_bootstrap to zip folder # This step is used to move JAR and `scf_bootstrap` files for HTTP-triggered Java functions. You only need to specify the `Jar` directory in `Serverless.yml` for event-triggered Java functions. Note that if you use Maven for compilation, you need to change the JAR path below to `/target`run: cp ./build/libs/XXX.jar ./scf_bootstrap ./zip- name: deploy serverlessuses: woodyyan/tencent-serverless-action@mainenv: # Environment variableSTAGE: dev # Your deployment environmentSERVERLESS_PLATFORM_VENDOR: tencent # The serverless platform is `aws` by default outside the Chinese mainland. Here, it is set to `tencent`TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }} # `secret ID` of your Tencent Cloud accountTENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }} # `secret key` of your Tencent Cloud account
# When the code is pushed to the `main` branch, the current workflow will be executed# For more information on configuration, visit https://docs.github.com/cn/actions/getting-started-with-github-actions.name: deploy serverless scfon: # Configuration of the event and branch listened onpush:branches:- mainjobs:deploy:name: deploy serverless scfruns-on: ubuntu-lateststeps:- name: clone local repositoryuses: actions/checkout@v2- name: install dependencyrun: npm install- name: buildrun: npm build- name: deploy serverlessuses: woodyyan/tencent-serverless-action@mainenv: # Environment variableSTAGE: dev # Your deployment environmentSERVERLESS_PLATFORM_VENDOR: tencent # The serverless platform is `aws` by default outside the Chinese mainland. Here, it is set to `tencent`TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }} # `secret ID` of your Tencent Cloud account, which needs to be configured in `Settings-Secrets`TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }} # `secret key` of your Tencent Cloud account, which needs to be configured in `Settings-Secrets`
TENCENT_SECRET_ID
and TENCENT_SECRET_KEY
are required during the deployment. You need to configure such variables in Secrets
in the GitHub code repository settings as follows:
serverless.yml
configuration file used for execution in Serverless Framework CLI.scf_bootstrap
file in the root directory of your project.pipeline {agent anystages {stage('check out') {steps {checkout([$class: 'GitSCM', branches: [[name: env.GIT_BUILD_REF]],userRemoteConfigs: [[url: env.GIT_REPO_URL, credentialsId: env.CREDENTIALS_ID]]])}}stage('Package'){ // This stage is only used for a Java projectsteps{container("maven") {echo 'Package start'sh "mvn package" // This line is used for a Java Maven projectsh "./gradlew build" // This line is used for a Java Gradle projectsh "mkdir zip" // This line is used to store JAR and `scf_bootstrap` files for HTTP-triggered Java functions. You only need to specify the `Jar` directory in `Serverless.yml` for event-triggered Java functions.sh "cp ./build/libs/XXX.jar ./scf_bootstrap ./zip" // This line is used to move JAR and `scf_bootstrap` files for HTTP-triggered Java functions. You only need to specify the `Jar` directory in `Serverless.yml` for event-triggered Java functions. Note that if you use Maven for compilation, you need to change the JAR path below to `/target`.}}}stage('Install dependency') {steps {echo 'Installing dependency...'sh 'npm i -g serverless'sh 'npm install' // This line is used for a Node.js projectecho 'Dependency installed.'}}stage('deploy') {steps {echo 'deploying...'withCredentials([cloudApi(credentialsId: "${env.TENCENT_CLOUD_API_CRED}",secretIdVariable: 'TENCENT_SECRET_ID',secretKeyVariable: 'TENCENT_SECRET_KEY'),]) {// Generate the credential filesh 'echo "TENCENT_SECRET_ID=${TENCENT_SECRET_ID}\\nTENCENT_SECRET_KEY=${TENCENT_SECRET_KEY}" > .env'// Deploysh 'sls deploy --debug'// Remove the credentialsh 'rm .env'}echo 'deployment complete'}}}}
TENCENT_SECRET_ID
and TENCENT_SECRET_KEY
required during the deployment from CAM.
Was this page helpful?