1
votes

So, I am trying to use Azure DevOps release pipeline and Packer to build a gold image but I am coming up with a weird error where the script is not found. I am trying to use the auto generated template as I am not experience with Packer at all but it seemed very straight forward so I persisted.

I am building off a base Ubuntu 18.04-LTS image, my package is being picked up from the CI pipeline fine and is visible in the UI. My package contains the script and this is also visible from the UI. I have no arguments for the script as it contains very little at this stage.

The initial step runs fine as per below and when I put in an incorrect script name or path it fails as I would expect.

2020-09-21T13:42:28.5763293Z Resolving deploy package path.
2020-09-21T13:42:28.5872208Z Resolved deploy package path: /agent/_work/r1/a/_APP/_drop/MyApp.Web.
2020-09-21T13:42:28.5873284Z Resolving deploy script path.
2020-09-21T13:42:28.7426014Z Resolved deploy script path: deploy.sh.

The build runs through packer validation fine and a machine is setup. The task successfully connects via SSH and logs show that it uploads as per below. It then fails because it can't find the script.

2020-09-21T13:43:51.9642183Z ==> azure-arm: Connected to SSH!
2020-09-21T13:43:51.9642706Z 
2020-09-21T13:43:51.9661411Z ==> azure-arm: Provisioning with shell script: /tmp/packer-shell391925162
2020-09-21T13:43:51.9678528Z 
2020-09-21T13:43:54.3568719Z ==> azure-arm: Uploading /agent/_work/r1/a/_APP/_drop/MyApp.Web => /deployTemp/MyApp.Web
2020-09-21T13:50:54.8214369Z 
2020-09-21T13:50:55.8696845Z ==> azure-arm: Provisioning with shell script: /tmp/packer-shell088825827
2020-09-21T13:50:55.8700537Z 
2020-09-21T13:50:55.9197460Z     azure-arm: MyApp.Web
2020-09-21T13:50:55.9198790Z 
2020-09-21T13:50:55.9211167Z     azure-arm: /tmp/script_5793.sh: 5: /tmp/script_5793.sh: /deployTemp/MyApp.Web/deploy.sh: not found

My initial thoughts are that the package was still in the process of copying across as the time stamp between the upload and trying to run the script is really quick and I know from other steps in the pipeline that copying the package generally takes a lot longer. I did try to run a user generated version of the script but keep getting blocked in other ways.

I have included the code from the deploy as it is only really an apt-get command which I was hoping to flesh out after once I had a successful test run but have yet to see any success.

Any help or suggestions would be greatly appreciated.

Step settings Settings as per below (written in GUI and copied to YAML)

steps:
- task: PackerBuild@1
  displayName: 'Build immutable image'
  inputs:
    ConnectedServiceName: '<Service Account>'
    managedImageName: AppNameGoldImageSept20
    location: australiaeast
    storageAccountName: astorageaccount
    azureResourceGroup: '<ResourceGroup>'
    baseImage: 'Canonical:UbuntuServer:18.04-LTS:linux'
    packagePath: '$(System.DefaultWorkingDirectory)/_APP/_drop/MyApp.Web'
    deployScriptPath: deploy.sh
    additionalBuilderParameters: '{\"vm_size\":\"Standard_D3_v2\",\"virtual_network_name\":\"<VNetHere>\",\"virtual_network_subnet_name\":\"<Subnet Here>\",\"virtual_network_resource_group_name\":\"<VnetRg>\"}'
1
Hi @Grae Saunders, could you share the task setting and full debug log here? - Vito Liu
Sorry for the late reply. - Grae Saunders
I have updated the question. Regarding full logs I would rather not share them as they take time to sanitise, rather could you be specific about what you may be looking for? - Grae Saunders
Hi @Grae Saunders, I want to check the .sh file path, by the way, have you checked this blog? I have tried it and it works. - Vito Liu
Hi Vito, Both the config and log extract show the .sh path. Regarding the blog that was the basis for a lot of what I have done with the only exception being that I was using a dot net app instead of the node js app. I was wondering if there is a more updated version of the blog as I know there have been some step changes in Az DevOps - Grae Saunders

1 Answers

0
votes

I had the same issue. However, it solved it.

It was a very simple issue. I changed the agent used to print the artifacts from Windows to Linux, and the issue was resolved.

I tried a lot with the contents of the following repositories, and conclusively confirmed that the agent that creates artifacts should be running on a Linux base. https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/PackerBuildV1/DefaultTemplates/custom.managed.linux.template.json

It's an old issue, but I hope it goes well.