CAR-CLI is a command line tool for managing application versions. You can use CAR-CLI to quickly and easily query, upload, update, and delete application versions by calling TencentCloud APIs. This document describes the basic features of CAR-CLI and how to use it to implement an automated pipeline for updating application versions. Basic features
Note:
You need to place the configuration file in the same directory as the CLI tool and replace with the SecretId
, SecretKey
, and AppId
of your Tencent Cloud account. CAR-CLI supports the macOS, Windows, and Linux operating systems. The following examples are based on Linux.
View help information
Run the following command to view the tool's help information.
For example, run the following command to view the help information for the application creation command.
./car create-application help
Create an application
Run the following command to create an application. You need to enter the application name, which can contain up to 16 Chinese characters, letters, digits, or hyphens (-). If this command is executed successfully, the application ID of the new application will be returned.
./car create-application --name xxx
Create an application version
Run the following command to create an application version. Up to five versions can be created for an application. You need to enter the application ID, version name, and application file format (ZIP, RAR, or 7z). If there are any versions in ApplicationUpdateCreating
, ApplicationUpdateNoReleased
, or ApplicationUpdateCreateFail
status, this command will be rejected. After the version is created successfully, you also need to upload the application version file and release the new version. If this command is executed successfully, the application version ID will be returned.
./car create-application-version --app-id app-xxx --name xxx --type zip
Upload an application version file
Run the following command to upload an application package for a new version. You need to enter the Application ID, local path of the application file (pay attention to the format differences between Windows and Linux), and the Application Version ID. Please ensure that both the Application ID and Application Version ID are accurate. If uploading the application via a URL, input the Application ID and the URL.
./car upload-application-version-file --app-id app-xxx --path C:\\\\data\\\\xxx.zip --version-id ver-xxx
./car upload-application-version-file --app-id app-xxx --path /data/xxx.zip --version-id ver-xxx
./car upload-application-version-file --app-id app-xxx --url xxx
Note:
After the application version file is uploaded successfully, if its version name and format are different from those used to create an application version, they will be replaced with those of the uploaded file.
If the upload fails during the creation of an application or an application version, you can still proceed with this command. You must ensure that the local file path is not changed.
Release an application version
Run the following command to release an application version. You need to enter the application ID and version ID.
./car set-version-online --app-id app-xxx --version-id ver-xxx
Delete an application version
Run the following command to asynchronously delete an application version. You need to enter the application ID and version ID. To check whether the version has been deleted successfully, you can query the list of application versions.
./car delete-application-version --app-id app-xxx --version-id ver-xxx
Display the list of application versions
Run the following command to display the list of application versions. You need to enter the application ID. To obtain the output version ID and version status of the oldest version, use the grep
and awk
commands.
./car describe-application-version --app-id app-xxx
./car describe-application-version --app-id app-xxx | grep -v "Inuse" | awk '{print $1}' | head -n 1
Pipeline for updating application versions
This section uses a Tencent Cloud CODING pipeline as an example to show you how to implement a pipeline for updating application versions. Download CAR-CLI
Load the remote configuration file into the current working directory.
cd workdir
wget "your config file url"
Run the following scripts to download the CAR-CLI tool.
cd workdir
mkdir pkg && cd pkg
wget https://github.com/tencentyun/car-cli/releases/download/v1.0.0/car.zip
unzip car.zip
mv ./car/linux/car ../
cd ..
chmod +x car
Download the application file of the new version
Configure the following scripts to download the application file of the new version.
cd workdir
wget $PackageURL # Configure `PackageURL` in pipeline environment variables
Create an application version
Create a new version for an existing application, upload the new application version file, and finally release the new version.
Note:
If the number of application versions exceeds 5, this script will automatically delete the oldest versions which are not in use.
cd workdir
# Query the list of application versions
output=$(./car describe-application-version --app-id $ApplicationID) # Configure `ApplicationID` in pipeline environment variables
lineCount=$(echo "$output" | wc -l)
# If the number of application versions exceeds 5, delete the oldest versions which are not in use
if [ $lineCount -ge 5 ];then
versionID=$(echo "$output" | grep -v "Inuse" | awk '{print $1}' | head -n 1)
./car delete-application-version --app-id $ApplicationID --version-id $versionID
fi
# Deleting an application version is an async operation, so you need to regularly check whether the version deletion was successful
waitTimes=0
while [ $lineCount -ge 5 ]
do
output=$(./car describe-application-version --app-id $ApplicationID) # Replace the `ApplicationID` with your actual `ApplicationID`
lineCount=$(echo "$output" | wc -l)
waitTimes=$((waitTimes+1))
if [ $waitTimes -gt 20 ]
then
echo "Error: Waiting too long to delete application version."
exit 1
fi
sleep 1
done
# Query the application file name and type by `PackageURL`
fileName=$(basename $PackageURL) # Configure `PackageURL` in pipeline environment variables
echo $fileName
fileType="${PackageURL##*.}"
echo $fileType
# Create an application version
output=$(./car create-application-version --app-id $ApplicationID --name $fileName --type $fileType)
# Upload the new application version file to the cloud
./car upload-application-version-file --app-id $ApplicationID --version-id $output --path $fileName
# Release the new version
./car set-version-online --app-id $ApplicationID --version-id $output
この記事はお役に立ちましたか?