Hello Ladies and Gentlemen,
Unfortunately, my accepted answer was wrong.
I eventually figured the problem out.
In Azure Pipelines when a Secret Variable is used, it is encourages that the Secret Variable is wrapped in an Environment variable for debugging purposes.
For example a YAML line in Azure Pipelines reads:
- task: InstallSSHKey@0
inputs:
knownHostsEntry: $(KNOWN_HOSTS)
sshPublicKey: $(PUBLIC_KEY)
sshKeySecureFile: 'id_rsa'
env:
KNOWN_HOSTS : $(aps-known-host)
PUBLIC_KEY : $(aps-tf-public-key)
The public key is a secret variable and will print in any log files without the environment variable alias as *
However in the above code, the use of the environment variable, any log files will contain PUBLIC_KEY instead of *
Azure Pipelines does not like environment variables for the sshPublicKey value and will give the "Could not get the base64 portion of the public SSH key" error and the pipeline will fail.
Therefore the secret variable must be used and not the environment variable. Note the KNOWN_HOSTS variable works as expected.
Hence the correct YAML synthax for the InstallSSHKey task is:
- task: InstallSSHKey@0
inputs:
knownHostsEntry: $(KNOWN_HOSTS)
sshPublicKey: '$(aps-tf-public-key)'
sshKeySecureFile: 'id_rsa'
env:
KNOWN_HOSTS : $(aps-known-host)
Other hints:
In windows, use git bash to get the public key value:
clip ~/.ssh/id_rsa.pub
This copies the contents of the public key to the clipboard.
When you create a secret variable in the Azure Pipeline library, paste the value.
Additionally, I always press backspace and delete the last letter of key and then retype the last letter.
Just in case an extra newline character was inserted.
I really hope the above helps and prevents hours of untold and unnecessary aggravation.
Take care, be safe and healthy.
Best Regards,
Nigel P