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.

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

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay