Goal: Publish generic Docker image; Deploy image to multiple operating environments (k8s namespaces) with differing configurations.
I am using the KubernetesManifest@0 task to create and populate k8s secret in a k8s namespace. I have 100's of namespaces to represent different customer environments. I am using a bash script in a task before running KubernetesManifest@0 task to populate kubernetesServiceConnection:. Specifically, the bash script uses az devops cli to retrieve the correct, full service connection name for the k8s namespace where I want to deploy the k8s secret.
Problem: KubernetesManifest@0 task appears to require a value for kubernetesServiceConnection: at Pipeline YAML compile time. It appears that I cannot generate a value for kubernetesServiceConnection: during run time.
How can I automatically set kubernetesServiceConnection: at run time?
Error: There was a resource authorization issue: "The pipeline is not valid. Job Deploy_Dev: Step input kubernetesServiceConnection references service connection $(kubernetesServiceConnection) which could not be found. The service connection does not exist or has not been authorized for use.
My code:
- deployment: Deploy_Dev
pool:
vmImage: $(vmImageName)
dependsOn: Derive_Variable_Values
variables:
kubernetesServiceConnection: $[ dependencies.Derive_Variable_Values.outputs['deriveVariableValues.kubernetesServiceConnection'] ]
environment: $(devOpsEnvironment)
strategy:
runOnce:
deploy:
steps:
- checkout: self
displayName: Checkout $(Build.Repository.Name)
This bash script shows that kubernetesServiceConnection expands to the correct string for my specifc service connection name(s)
- task: Bash@3
displayName: Echo kubernetesServiceConnection
inputs:
targetType: 'inline'
script: |
echo kubernetesServiceConnection is $(kubernetesServiceConnection)
The above echo provides a correct string for kubernetesServiceConnection
- task: KubernetesManifest@0
displayName: Create k8s secret with Key Vault values
inputs:
action: createSecret
secretType: generic
secretName: $(keyVaultSecretName)
secretArguments: --from-literal=kvclientid=$(kvClientId) --from-literal=kvclientsecret=$(kvClientSecret) --from-literal=kvurl=$(kvUrl)
kubernetesServiceConnection: $(kubernetesServiceConnection)
namespace: $(k8sFullNamespace)
kubernetesServiceConnection: $(kubernetesServiceConnection) does not get a chance to resolve