Use Alibaba Cloud codeup tool pipeline to publish services

1. Back-end release (take the springboot project as an example)

Img

1. Create a new pipeline

Img

2. Choose a template

Select different templates according to different development environments, or directly select a blank template.

3. Select the code source

image-20220411111054920

Select the repository and default branch that you want to automate publishing.

4. Code specification scanning and unit testing

1. Code specification scan

Static scan -> java code specification scan

image-20220411113812868

2. maven unit test

mvn -B test -Dmaven.test.failure.ignore=true
mvn surefire-report:report-only
mvn site -DgenerateReports=false
复制代码

image-20220411113859795

3. Running logs and results

Click to view the running results

image-20220411114048835

5.java build upload

image-20220411111505240

Add steps

1.java build

Select the JDK version, maven version, and configure the build command.

mvn -B clean package -Dmaven.test.skip=true -Dautoconfig.skip
复制代码

2. Build upload

image-20220411114126924

The package path is target/package name

The package name is the package name in pom.xml

image-20220411115231993

6. Host Deployment

image-20220411115312131

  • Artifacts Upload successfully generated artifacts for Java builds

  • The release host is deployed on the internal/external network host through the agent

  • New host --> own host

image-20220411115553198

  • The copy command is executed on the host that needs to be deployed. After the agent is installed successfully, the host will be displayed in the annotation list

image-20220411133244584

  • Download path configuration (that is, the file path on the host to be deployed)

  • Department script placement

    tar zxvf /home/allbs/test/package.tgz -C /home/allbs/test/
    cd /home/allbs/test
    kill -9 $(netstat -tlnp | grep :8888 | awk '{print $7}' | awk -F '/' '{print $1}')
    java -jar -Dspring.profiles.active=prod test-0.0.1-SNAPSHOT-SNAPSHOT.jar 2>&1 &
    复制代码

    image-20220411120107505

7. Pipeline operation

image-20220411130431394

2. Publish front-end static resources

1. Configure the pipeline source (same as the backend)

2. Host deployment

image-20220411131127118

  • Download artifacts when deploying unchecked

  • Product selection is empty

  • The host group is the published internal/external network server (the method of adding servers is the same as the back-end part)

  • The download path is the static resource configuration path on the server (that is, the path configured in nginx)

echo ${GIT_REPO}
echo ${GIT_BRANCH}
echo ${COMMIT_ID}
cd /home/allbsweb
git fetch --all && git reset --hard origin/${GIT_BRANCH} && git pull
复制代码

3. Modify the content of the static resource configuration file

You can modify the configuration file by adding a new host deployment task and using its own [deployment script] sed command

// 进入服务器上静态资源目录
cd /home/allbsweb
// 删除共通js中20到94行的内容
sed -i '20,94d' common.js
// 在第19行后添加内容为"var tt = "1234";",如果需要有引号包裹请使用双引号
sed -i '19a var tt = "1234";' common.js
复制代码

4. npm package

The packaging method is the same as the steps for modifying static resource files

[New task] -> [Select task group -> [Host deployment] Execute the command you need to execute in the deployment script

3. Other

1. Premise

The server needs to configure the required environment in advance to run the service, such as jdk environment, node, git, etc.

When publishing static resources, you need to let the server remember the git account password in advance when pulling through git.

2. Remember git account password

1. Enter the root directory, command: cd /

2. Create a file to record the account password, command: touch .git-credentials

3. Open the file with vi, command: vi .git-credentials

4. Press i to enter edit mode

5. Enter https://{username}:{password}@github.com, in which, replace {username} with your account and {password} with your password. These two can be entered casually, but the subsequent warehouse Address must be accurate

6. Press Esc, then :wq, save and exit

7. Let git read the file just created, command: git config --global credential.helper store

8. Perform a git operation, such as git clone xxxxxx, and then enter the account password, this time the account password will be recorded, and you do not need to enter it again in the future

Guess you like

Origin juejin.im/post/7085216605394698276