DEV Community

Fakhrulhilal M
Fakhrulhilal M

Posted on

3 2

Applying CI/CD for classic ASP project

A new challenge to add CI/CD support for classic ASP. You might be wondering why I take care of classic ASP project for nowadays😂. But I believe one of you know the reason already😁. Classic ASP project doesn't have configuration system by default. It used to store in ordinary ASP file and place anything in VBscript variables, f.e. config.asp. Fortunately, they used to store in centralized place, so we don't have to scan all configurations in many files.
So the basic idea is simple, introduce placeholder format and replace it before deploying. Let's use #PLACEHOLDER# as an example. I prefer to use all caps so I can pay attention easily what needed to be changed. See example below:

<%

Dim cfgSocials
Set cfgSocials = Server.CreateObject("Scripting.Dictionary")
cfgSocials.Add "github", "#SOCIAL_GITHUB#"
cfgSocials.Add "twitter", "#SOCIAL_TWITTER#"
cfgSocials.Add "linkedin", "#SOCIAL_LINKEDIN#"
cfgSocials.Add "email", "#SOCIAL_EMAIL#"

Dim cfgSite
Set cfgSite = Server.CreateObject("Scripting.Dictionary")
cfgSite.Add "name", "Portofolio"
cfgSite.Add "fullname", "#FULL_NAME#"
cfgSite.Add "address", "#ADDRESS#"

%>
Enter fullscreen mode Exit fullscreen mode

After that, all we need to do read file content, and do find-replace based on placeholder. I'm a fan of powershell, because it's easy to write the script and its dotnet support is deadly insane👍. Here's the quick snippet

function Get-Value([string]$Key) {
    $Value = $Configs[$Key]
    if (-not([string]::IsNullOrEmpty($Value))) {
        $Value
    } else {
        [System.Environment]::GetEnvironmentVariable($Key)
    }
}

$PlaceholderPattern = [regex]::new('#(?<placeholder>\w+)#')
$ParsedContent = Get-Content -Path $Path | %{
    $PlaceholderPattern.Replace($_, {
        param($Match)
        if ($Match.Success) {
            $Value = Get-Value -Key $Match.Groups['placeholder'].Value
            if (-not([string]::IsNullOrEmpty($Value))) {
                $Value
            } else {
                $Match.Value
            }
        } else {
            $Match.Value
        }
    })
}
Set-Content -Path $Path -Value $ParsedContent
Enter fullscreen mode Exit fullscreen mode

In azure pipeline, it exposes all variables to environment variables. So it's easy to populate from pipeline definition to file.

Take a look at demo repo and give me feedback😊. I put all the details there.

Please say "thank you" by commenting on this post!

Everyone is welcome

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay