[英]upload jenkins build revision to s3 without triggering codedeploy
[英]How to upload a release (package with substitued variables) to S3 in order to deploy it with codedeploy
我嘗試將AWS Code Deploy與自動縮放組一起使用。 過去我是用章魚進行部署的,我想遷移到aws。
因此,我有一個包含多個步驟的章魚項目。 第一步是部署一個cloudformation模板,該模板將構建基礎架構:vpc,子網,部署組,自動擴展組,ELB,S3存儲桶等。
其他步驟應替換八達通程序包的變量,並從第一步中檢索S3存儲桶名稱,以將其上載到S3。
章魚我怎么能做到這一點?
謝謝。
這是我實現的方式:
在部署程序包的步驟中,單擊配置功能
選擇自定義部署腳本
將此腳本添加為部署腳本。 替換變量后,它將上傳到AWS S3存儲桶。
$sourcePath = $OctopusParameters["Octopus.Action.Package.InstallationDirectoryPath"] $destinationPath = $OctopusParameters["Your parameter to the full path where you want the Zip file stored"] $destinationPathRootDirectory = $OctopusParameters["Your parameter to the folder"] Write-Host "Cleaning up previous zip files" Remove-Item "$destinationPathRootDirectory\\*.zip" Write-Host "Compressing $sourcePath to $destinationPath" Compress-Archive -Path "$sourcePath\\*" -DestinationPath $destinationPath -Force $params = @{} #Initialises the S3 Credentials based on the Access Key and Secret Key provided, so that we can invoke the APIs further down Set-AWSCredentials -AccessKey $AwsAccessKey -SecretKey $AwsAccessSecret -StoreAs S3Creds #Initialises the Default AWS Region based on the region provided Set-DefaultAWSRegion -Region $AwsRegion #Gets all relevant files and uploads them function Upload($item) { #Gets all files and child folders within the given directory foreach ($i in Get-ChildItem $item) { #Inserts file to AWS Write-S3Object -ProfileName S3Creds -BucketName $S3BucketName -Key $($i.Name) -File $i.FullName @params } } Upload($destinationPath)
添加一個步驟以運行將執行部署的AWS命令行命令。
這是該步驟中的示例腳本:
# All these parameters are parameters you set in the variables screen in Octopus Deploy
Write-Host "ApplicationName $AwsApplicationName"
Write-Host "DeploymentConfigName $AwsCodeDeployConfigName"
Write-Host "CodeDeployName $AwsCodeDeployGroupName"
Write-Host "BucketLocation $S3BucketName"
Write-Host "KeyName $ZipFileName"
# This is the AWS name of the location where you want to put the bucket, such as us-west-1
Write-Host "BucketLocation $bucketLocation"
$fullyQualifiedBucket = "$S3BucketName-$bucketLocation"
Write-Host "Fully Qualified Bucket $fullyQualifiedBucket"
$deployment = aws deploy create-deployment --application-name $AwsApplicationName --deployment-config-name $AwsCodeDeployConfigName --deployment-group-name $AwsCodeDeployGroupName --s3-location bucket=$S3BucketName,bundleType=zip,key=$TradingWebSiteZipFileName
Write-Host "Deployment info $deployment"
它確實在S3存儲桶中為每個環境創建了一個唯一的程序包。 因此,您將不得不考慮這一點。 它不是世界上最完美的解決方案,如果您遍歷它並找到更好的解決方案,請告訴我!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.