Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Team City] Working with Projects and Build Configurations

Posted on July 26, 2022March 1, 2024 By nim No Comments on [Team City] Working with Projects and Build Configurations

Contents

Toggle
  • 1) Connecting to a Version Control System (VCS)
  • 2) VCS Root Connections and Open Authentication
  • 3) Ways of organizing your projects in TeamCity
  • 4) Creating your first TeamCity project
  • 5) Tools, Build Steps, Parameters and Templates!
  • 6) How to use the Environment (env) of TeamCity
    • With Linux Agents
    • With Windows Agents
  • Get environment/parameter hidden on teamcity
  • Get the branch name or tag name when TeamCity runs the pipeline.
    • Issues when using the branch name to attach a tag for the docker image

1) Connecting to a Version Control System (VCS)

Gần như là khi chúng ta cấu hình connection to get ở Root Project thì các project khác sẽ được thùa hưởng
Bạn điền đầy đủ các thông tin như hình.
với authentication thì bạn chọn user/<Personal access tokens>

https://github.com/mrnim94/Accounting

bạn có thể kiêm tra để biêt teamcity kết nối với github được chưa?
sau khi connection successful thì bạn click “create”

2) VCS Root Connections and Open Authentication

Ở phần 1 chúng ta đã khai báo username/token github
Phần này chúng ta cần để tạo project dựa trên các repo trên github.
Mình ví dụ mình muốn tạo 1 project cho repo Accouting

Giờ ta vào github cấu hình

GitHub Request Error
Invalid callback URL specified in GitHub OAuth application. Callback URL should be: http://192.168.101.34:8111/oauth/github/accessToken.html
Bạn thấy là nó list ra các repo
chọn 1 repo
Phân này chúng ta tạm dừng ở đây

3) Ways of organizing your projects in TeamCity

Projects tend to group build configurations
Build configurations include the instructions of building and deploying code
Root Project
Build and Package (Project)
Accounting
Fixed Asset
Deployments (Project)
Accounting

Root Project
Accounting (Project)
Build and package
Deploy to QA environment
Deploy to Production environment
Fixed Assets (Project)
Build and package
Deploy to QA environment
Deploy to Production environmen

4) Creating your first TeamCity project

Đầu tiên bạn cần tạo 1 project

tạo 1 project với tyle là manually
Xong rồi click create
sau khi bạn nhấn create thì nó sẽ hiện ra màn hình như sau

Giờ đến phần chúng ta tạo Build Configurations trong project

Bạn thấy nó detect và scan repo tên là Accounting
https://github.com/mrnim94/Accounting
và đây là kết quả
Bạn thấy chúng ta đã có 1 project và 1 build trong project đó!

5) Tools, Build Steps, Parameters and Templates!

thử click run
Bạn sẽ thấy 2 agent ở đây chạy chạy
Trở lại chỗ này thì mình thấy có thông báo “SUCCESS“
Vào đây bạn sẽ thấy được build log
Ở hiện tại bạn nhìn thôi nhé

6) How to use the Environment (env) of TeamCity

https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html#Predefined+Server+Build+Parameters
https://docs.testfairy.com/Continuous_Integration/TeamCity.html

In TeamCity, add a environment variable as a New Parameter in to the Build Configuration

Name the parameter env.TESTFAIRY_API_KEY and give it the value you copied from the TestFairy preferences page, and Save.

Add a Build Step to the Build Configuration you wish to deploy from.

Make sure to select a Command Line build step.

Copy the following command into Custom script text field

curl https://upload.testfairy.com/api/upload -F api_key=${env.TESTFAIRY_API_KEY} -F comment="TeamCity build" -F file=@android.apk

With Linux Agents

BUILD_NUMBER=%env.BUILD_NUMBER%
docker tag "${!DYNAMIC_IMG_NAME}" "${!DYNAMIC_IMG_NAME}-${BUILD_NUMBER}"
docker push "${!DYNAMIC_IMG_NAME}-${BUILD_NUMBER}"
branch_name="%teamcity.build.branch%"
# Replace '/' with '_' in branch name
formatted_branch_name=${branch_name//\//_}

# Sử dụng cú pháp $() để chèn biến formatted_branch_name vào JSON
json_payload=$(cat <<EOF
{
  "git-branch": "${formatted_branch_name}",
  "integration-command": "node index.js -e staging -a integration",
  "delay-in-seconds": "600"
}
EOF
)

curl -X POST https://spinner.nimtechnology.com/webhook \
     -H 'Content-Type: application/json' \
     -H "Authorization: %env.INTEGRATION_TOKEN%" \
     -d "$json_payload"

Trong đoạn mã trên, chúng ta sử dụng cú pháp $(cat <<EOF ... EOF) để tạo một chuỗi JSON có chứa biến formatted_branch_name. Cách làm này đảm bảo rằng giá trị của formatted_branch_name được đánh giá và thay thế vào chuỗi JSON trước khi câu lệnh curl được thực thi.

Nếu sau khi áp dụng cách trên mà bạn vẫn gặp vấn đề với việc truyền giá trị biến vào JSON, hãy đảm bảo rằng biến formatted_branch_name có giá trị mong muốn trước khi thực thi lệnh curl. Bạn có thể kiểm tra điều này bằng cách thêm echo "${json_payload}" trước câu lệnh curl để in ra nội dung của biến json_payload và xác nhận rằng nó chứa giá trị đúng của formatted_branch_name.

With Windows Agents

docker tag $env:DOCKER_IMAGE_WIN $env:DOCKER_IMAGE_WIN-$env:BUILD_NUMBER
docker push $env:DOCKER_IMAGE_WIN-$env:BUILD_NUMBER

Get environment/parameter hidden on teamcity

https://youtrack.jetbrains.com/issue/TW-59165?_ga=2.128595276.1379635287.1673260545-609699531.1660623895&_gl=11y9yvg8_gaNjA5Njk5NTMxLjE2NjA2MjM4OTU._ga_9J976DJZ68*MTY3MzI2MDU0NC40NC4xLjE2NzMyNjE1MzEuMC4wLjA.

set -eux
auth="$(echo -n "$USER:$PASSWORD" | base64)"
echo "##teamcity[hide text='$auth']"
# Other code


echo cvbjNEVQ== | base64 --decode

Get the branch name or tag name when TeamCity runs the pipeline.

Bạn sẽ muốn lấy branch name hoặc tag name để gắn làm tag cho image khi build docker.

$vcsRoot = "%teamcity.build.branch%"
Write-Host $vcsRoot

aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin "$env:AWS_ACCOUNT.dkr.ecr.us-west-2.amazonaws.com"
docker tag $env:DOCKER_IMAGE_WIN $env:DOCKER_IMAGE_WIN-$env:BUILD_NUMBER-"%teamcity.build.branch%"
docker push $env:DOCKER_IMAGE_WIN-$env:BUILD_NUMBER-"%teamcity.build.branch%"

Issues when using the branch name to attach a tag for the docker image

Khi branch name là: feature/NIM-297
thì docker image là: XXXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/nim_resultmq:dev-45331401-linux-1694-feature/NIM-297

Error parsing reference: "XXXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/nim_resultmq:dev-45331401-linux-1694-feature/NIM-297" is not a valid repository/tag: invalid reference format
invalid reference format
Error response from daemon: invalid reference format

chúng ta sẽ cần replace “/” sang “_”

trên Linux:

# Original branch name
branch_name="%teamcity.build.branch%"
# Replace '/' with '_' in branch name
formatted_branch_name=${branch_name//\//_}


docker push "XXXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/nim_resultmq:dev-45331401-linux-1694-$formatted_branch_name"

Trên Windows:

# Original branch name
$branch_name = "%teamcity.build.branch%"
# Replace '/' with '_' in branch name
$formatted_branch_name = $branch_name -replace "/", "_"

docker push XXXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/nim_resultmq:dev-45331401-linux-1694-"$formatted_branch_name"
TeamCity

Post navigation

Previous Post: [TeamCity] Installing and configuring TeamCity 2017
Next Post: [TeamCity] Kotlin DSL – Lesson 1: Project Setup

More Related Articles

[Teamcity] How does TeamCity login and pull/push images to the private Docker HUB TeamCity
[TeamCity] Kotlin DSL – Lesson 1: Project Setup TeamCity
[Teamcity] What is “reverse.dep.*” on TeamCity TeamCity
[TeamCity] Installing and configuring TeamCity 2017 TeamCity
[Teamcity] Kotlin codes on Git(repository) are conflicted with the TeamCity UI. TeamCity
[Teamcity] Why does TeamCity can’t find tag and branch on git TeamCity

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Azure] The subscription is not registered to use namespace ‘Microsoft.ContainerService’ May 8, 2025
  • [Azure] Insufficient regional vcpu quota left May 8, 2025
  • [WordPress] How to add a Dynamic watermark on WordPress. May 6, 2025
  • [vnet/Azure] VNet provisioning via Terraform. April 28, 2025
  • [tracetcp] How to perform a tracert command using a specific port. April 3, 2025

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.