Create pipeline for deployment
Closed this issue · 8 comments
Initial tasks:
-
Configure Azure Jenkins instance to point to the ICOKPy registry
1.1 Attempt 1 (failed) - configured at the end of the project web config page, credentials from portal.azure. Appears to be attempting to access the registry via git? See http://localhost:8080/blue/organizations/jenkins/OK/detail/PR-15/6/pipeline
1.2 Comment - 1.1 is looking at the problem backwards; Jenkins should continue to default to Dockerhub, and only reference the ICOKPy registry when pushing post-master-success. So the hack needed here is working out how to get an in-repo Jenkinsfile to access credentials stored locally in the Jenkins instance.
1.3 Attempt 2(a) - Try using the method documented at: https://jenkins.io/doc/book/pipeline/docker/#custom-registry ; created a branch ( jenkins/dummy-push-to-custom-repo ) to try pushing a test image to the registry as proof of concept.
1.4 Hit a snag in terms of writing all the Jenkins config in declarative pipeline - doesn't appear to be a way to push the image from declarative; the supported method is docker.withregistry(...) in scripted.
1.5 Fix 1.4 by wrapping the post{} section in script {} ; this will at some point become deprecated and need to be updated to declarative. This appears to be working, using:
https://github.com/icokpy/ok/blob/jenkins/dummy-push-to-custom-registry/Jenkinsfile
and running through Jenkins with:
http://ok-jenkins.uksouth.cloudapp.azure.com/blue/organizations/jenkins/OK/detail/jenkins%2Fdummy-push-to-custom-registry/14/pipeline -
Pushes should only happen when building master branch.
2.1. Trying: when { branch 'master' } conditional in the post {} stage - fails but with no useful logs available
2.2 Trying putting the conditional when{} before the post{} stage - still fails
2.3 Wrap the scripted docker step in an if{} - works. -
Docker tags should be set appropriately / uniquely through the build
3.1 Environment variables don't get substituted correctly in the Jenkinsfile - fixed by switching from single-quote to double-quote strings
3.2 Docker tags must be all lower case - fixed by pre-formatting env.BUILD_TAG to lower case
3.3 NOTE - going to cause problems with special characters (notably, percentage) in tags
PR merged into master - check the registry when build completes to see whether the built image was published.
It dind't; fixing with a general rewrite as per PR #32
Notes on az cli deployment:
- Documentation on deploying at https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-deploy-cli
- Answer for az login credential handling on https://stackoverflow.com/questions/45979852/using-azure-cli-in-jenkins-pipeline
- Creating a service principal - https://docs.microsoft.com/en-us/cli/azure/create-an-azure-service-principal-azure-cli?toc=%2Fazure%2Fazure-resource-manager%2Ftoc.json&view=azure-cli-latest
- MSFT documentation on Jenkins Azure cli via pipeline - https://docs.microsoft.com/en-us/azure/jenkins/execute-cli-jenkins-pipeline
- GH repo with example deployment via Jenkinsfile - https://github.com/azure-devops/javawebappsample
To-do list:
- Create / obtain a service principal --DONE
- Add service principal to Jenkins --DONE
- Add az cli deployment comomand to Jenkinsfile -- IN BRANCH jenkins/add-deploy-code, not merged
PR #38 aims to close this issue
Now returning a region error:
ERROR: Deployment failed. Correlation ID: 0d8c01c5-db52-469c-83dc-08e706b1c3f0. {
"error": {
"code": "LocationNotAvailableForResourceType",
"message": "The provided location 'uksouth' is not available for resource type 'Microsoft.ContainerInstance/containerGroups'. List of available regions for the resource type is 'westus,eastus,westeurope,westus2,northeurope,southeastasia'."
}
}
Fix for region in PR #54
Deploying correctly to dev