To date, ApexSQL CI/CD toolkit was able to successfully execute CI/CD pipelines in TeamCity server using PowerShell runner with CI and CD PowerShell scripts.
Creating build configurations can be accomplished through PowerShell script using ApexSQL CI/CD toolkit cmdlets. For example, to configure the BUILD step, open the ApexSQL CI PowerShell script example.
First, with -Options parameter referring to general options:
$options = New-ApexSqlOptions -PipelineName "CI_Pipeline" -NotificationSettings $notificationSettings
Now, initial configuration for the source would look like this:
$dsSC = New-ApexSQLSource -ConnectionName "git_source" -Source_Type "git" -Repository "https://email@example.com/dev_alpha/alpha_prj_src.git/Prj_repo/" -Branch "master" -UserName "firstname.lastname@example.org" -Password "dsSC-password"
Note: “dsSC-password” is the name of the file (without it’s extension) where user’s password is stored in encrypted form. This should be done before the configuration of the CI script by following command:
read-host -AsSecureString | ConvertFrom-SecureString | Out-File "c:\PSscriptFolderPath\Passwords\dsSC-password.txt"
Next is the configuration for the target database connection:
$dsQA = New-ApexSqlDatabaseConnection -ConnectionName "qaDB_dest" -Server "ARRAKIS\SQLEXPRESS" -Database "test_2014" -WindowsAuthentication
Finally, the build step with its parameters would be configured like this:
Invoke-ApexSqlBuildStep -Options $options -Source $dsSC -Database $dsQA | Out-Null
All these configurations have to be set up manually before using with TeamCity Build configuration.
When the Build step configuration is done, the TeamCity runner will be set up and configured to run successfully.
Setting TeamCity Build configuration with ApexSQL PowerShell cmdlets
Providing that the project and build configuration inside TeamCity build server was created, it is possible to set up the build using PowerShell cmdlets.
From created build configuration choose Build Steps option and in the new view click on Add Build Step button to open the New Build Step view for setting the build step. Here, from selection dropdown menu choose PowerShell Runner type:
In the PowerShell runner configuration view field Script needs to be set on File and in Script file field the path to the repository where ApexSQL CI example script is located needs to be entered. After clicking on Save, the BUILD step will be ready for execution:
Any later change to CI configuration needs to be done within the ApexSQL CI example script and synced with the repository.
Set up TeamCity build with ApexSQL plugin
To install ApexSQL CI/CD toolkit TeamCity plugin, go to the Administration panel of TeamCity build server then, from the left panel view options choose Plugins list view:
From this view, click on the Upload plugin zip button and then in the opened dialogue box browse for the plugin zip file obtained from ApexSQL Downloads page:
After the upload a restart of TeamCity build server is needed before plugin becomes available. It can be seen in the External plugins section of the Plugin list view:
Now it is possible to create projects and build configurations in a similar manner with one noticeable difference. When the view for adding new step or editing existing one is opened, inside the dropdown menu for choosing the build runner type we can see new items. These items represent the steps available from ApexSQL CI/CD toolkit TeamCity plugin:
Once selected each step can be configured according to its purpose. In order for step to work corresponding ApexSQL tool is necessary to be installed with the build agent for use on TeamCity build server.
With the ApexSQL CI/CD toolkit TeamCity plugin installed on TeamCity build server the use of PowerShell script for executing CI and CD pipelines is no longer needed. Configuring steps can be done from TeamCity GUI with few easy steps.
To create and configure Build step using ApexSQL CI/CD toolkit TeamCity plugin, go to the Build Configuration Page and in Build steps view click on Add build step button:
With the ApexSQL plugin present, when selecting the Runner type, in selection menu will be new runners from ApexSQL CI/CD toolkit. For the Build step choose ApexSQL CI/CD toolkit – Build:
Step configuration view will open where step parameters can be entered:
With a click on the Save button configuration step will be finished and step will be added to the build configuration.
When all needed steps are configured like this, the Build configuration will be ready to execute.
In case there are changes needed to be done to a step, just open the Build Steps view from the Build configuration, click on a step that needs changing, change the values in the field and click the Save button.
June 6, 2018