Hi Team,
I have been struggling with weird issue recently, I know its not related to Octopus functionality but I want to achieve this functionality via Octopus hence asking this question here.
I store the Certificate Private Key, Certificate Body and Certificate Chain in the Octopus variables manually. Now I want to import this into AWS ACM using AWS Cli. However whenever I run code down below at end of post, it errors out due to “-----BEGIN CERTIFICATE-----” and “-----END CERTIFICATE-----” these lines in the certificate. So to trim down the issue further I am only trying to save the Octopus variable with cert details into local file but its failing with this error -
ParserError: At E:\Octopus.Tentacle.v4\v4-octopus.deploy.internal.cba\Work\20220202110419-711063-1116\Script.ps1:1 char:17
February 2nd 2022 22:04:25
Error
- $certBody = -----BEGIN CERTIFICATE-----
February 2nd 2022 22:04:25
Error
- ~
February 2nd 2022 22:04:25
Error
Missing expression after unary operator ‘–’.
February 2nd 2022 22:04:25
Error
At E:\Octopus.Tentacle.v4\v4-octopus.deploy.internal.cba\Work\20220202110419-711063-1116\Script.ps1:1 char:17
February 2nd 2022 22:04:25
Error
- $certBody = -----BEGIN CERTIFICATE-----
February 2nd 2022 22:04:25
Error
February 2nd 2022 22:04:25
Error
Unexpected token ‘-BEGIN’ in expression or statement.
February 2nd 2022 22:04:25
Error
At E:\Octopus.Tentacle.v4\v4-octopus.deploy.internal.cba\Work\20220202110419-711063-1116\Script.ps1:1 char:24
February 2nd 2022 22:04:25
Error
- $certBody = -----BEGIN CERTIFICATE-----
February 2nd 2022 22:04:25
Error
February 2nd 2022 22:04:25
Error
Unexpected token ‘CERTIFICATE-----’ in expression or statement.
February 2nd 2022 22:04:25
Error
At E:\Octopus.Tentacle.v4\v4-octopus.deploy.internal.cba\Work\20220202110419-711063-1116\Script.ps1:12 char:3
February 2nd 2022 22:04:25
Error
- 4+mOIcrKAcPgDx5kA5FMkwfxJUXrnqxxfjFAfxj2pn7RFIzvoCWM6ZxZNf9GgnOT
February 2nd 2022 22:04:25
Error
- ~
February 2nd 2022 22:04:25
Error
You must provide a value expression following the ‘+’ operator.
February 2nd 2022 22:04:25
Error
At E:\Octopus.Tentacle.v4\v4-octopus.deploy.internal.cba\Work\20220202110419-711063-1116\Script.ps1:12 char:3
February 2nd 2022 22:04:25
Error
- 4+mOIcrKAcPgDx5kA5FMkwfxJUXrnqxxfjFAfxj2pn7RFIzvoCWM6ZxZNf9GgnOT
February 2nd 2022 22:04:25
Error
February 2nd 2022 22:04:25
Error
Unexpected token ‘mOIcrKAcPgDx5kA5FMkwfxJUXrnqxxfjFAfxj2pn7RFIzvoCWM6ZxZNf9GgnOT’ in expression or statement.
February 2nd 2022 22:04:25
Error
At E:\Octopus.Tentacle.v4\v4-octopus.deploy.internal.cba\Work\20220202110419-711063-1116\Script.ps1:36 char:3
February 2nd 2022 22:04:25
Error
- 2+KBdo0IVu4A3bPHRfliSJl7Exo118zifIgMCh5d6cETER6MHT2lgObHUzDKX4XD
February 2nd 2022 22:04:25
Error
- ~
February 2nd 2022 22:04:25
Error
You must provide a value expression following the ‘+’ operator.
February 2nd 2022 22:04:25
Error
At E:\Octopus.Tentacle.v4\v4-octopus.deploy.internal.cba\Work\20220202110419-711063-1116\Script.ps1:36 char:3
February 2nd 2022 22:04:25
Error
- 2+KBdo0IVu4A3bPHRfliSJl7Exo118zifIgMCh5d6cETER6MHT2lgObHUzDKX4XD
Below is my code in the AWS CLI step of Octopus -
$certBody = #{CertBody}
Set-Content -Path .\PrivateKey.key -Value $certBody
Where value of #{CertBody} is something like below (truncated actual value for demo purpose)
-----BEGIN CERTIFICATE-----
MIIHpTCCBY2gAwIBAgITUAADbxDFrPNPOXV8igAAAANvEDANBgkqhkiG9w0BAQsF
ADCBpDELMAkGA1UEBhMCQVUxGDAWBgNVBAgTD05ldyBTb3V0aCBXYWxlczEPMA
DX0eNWCltqdUAQqVdVCBeiSndMJGS+Gb5MDkOLIcaq1zjgtVcOXLGIa+o+B3nUoG
0VT0hK3sH2Gt4E2uhHWIt0Q360KYUTUfgMkg1eiDNr+TWcKWm3lU548=
-----END CERTIFICATE-----