Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

PrePostDeploymentScript.ps1 is not recognized as a name #5

Closed
hedglenrm opened this issue Nov 29, 2021 · 9 comments
Closed

PrePostDeploymentScript.ps1 is not recognized as a name #5

hedglenrm opened this issue Nov 29, 2021 · 9 comments

Comments

@hedglenrm
Copy link

hedglenrm commented Nov 29, 2021

I recieved this error when attempting to run the PrePostDeploymentScript.ps1.

Run Azure/[email protected]
Run Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
Run /runner/_work/_actions/Azure/data-factory-deploy-action/v1.1.0/PrePostDeploymentScript.ps1 `
/runner/_work/_actions/Azure/data-factory-deploy-action/v1.1.0/PrePostDeploymentScript.ps1: /__w/_temp/5e4eb6bf-0270-4c39-a3ca-b7c9dd356331.ps1:2
Line |
   2 |  /runner/_work/_actions/Azure/data-factory-deploy-action/v1.1.0/PrePos …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The term
     | '/runner/_work/_actions/Azure/data-factory-deploy-action/v1.1.0/PrePostDeploymentScript.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program.

Thank you

@hedglenrm
Copy link
Author

Here is my workflow file.


name: Testbuild
on:
  push:
    branches:
      - develop

jobs:
  
  quality:
    runs-on: [self-hosted, azure]
    name: "Build Release ARM"
    steps:
      - uses: actions/checkout@v2
      - name: Get Azure credentials from Vault
        id: secrets
        uses: hashicorp/[email protected]
        with:
          url: https://vault.tools.dcsg.com
          method: approle
          roleId: ${{ secrets.VAULT_ROLE_ID }}
          secretId: ${{ secrets.VAULT_SECRET_ID }}
      - name: Azure Login
        uses: azure/login@v1
        env: 
          AZURE_CREDENTIALS: "${{ toJson(steps.secrets.outputs) }}"
        with:
          creds: ${{ env.AZURE_CREDENTIALS }}
      - name: Export ARM Template
        id: export
        uses: Azure/[email protected]
      - name: Deploy resources
        uses: Azure/[email protected]
        with:
          resourceGroupName: athlete-data-hub-prod
          dataFactoryName: adf-adh-prod
          armTemplateFile: ${{ steps.export.outputs.arm-template-directory }}/ARMTemplateForFactory.json
          # armTemplateParametersFile: ${{ steps.export.outputs.arm-template-directory }}/ARMTemplateParametersForFactory.json

@fedeoliv
Copy link
Contributor

Hi @hedglenrm could you please try upgrading the Azure/data-factory-export-action version to 1.1.0? We've made some improvements on the latest version to embed the PrePostDeploymentScript pwsh script into the action so developers don't need to host it on their git repos.

@hedglenrm
Copy link
Author

Hi @fedeoliv I changed the version of Azure/data-factory-export-action to 1.1.0, but still received the same error. the Azure/data-factory-deploy-action is not finding the PrePostDeploymentScript for some reason. I see it exists in the repository.

@fedeoliv
Copy link
Contributor

fedeoliv commented Dec 1, 2021

@hedglenrm what is your self-hosted runner OS platform? I'm wondering if this could be something related to cross platform directory path. This is how the action invokes the powershell script:

 ${{ github.action_path }}/PrePostDeploymentScript.ps1

Could you please try running it on ubuntu-latest runner to see if the error persists? I have a working sample here that is similar to your action but running on ubuntu.

@hedglenrm
Copy link
Author

Thank you I'll give it a try.

@hedglenrm
Copy link
Author

hello @fedeoliv when using the sample you provided, I get an error when logigng into powershell.

Running Azure PS Login
/usr/bin/pwsh -Command try ***
            $ErrorActionPreference = "Stop"
            $WarningPreference = "SilentlyContinue"
            $output = @***
            $data = Get-Module -Name Az.Accounts -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1
            $output['AzVersion'] = $data.Version.ToString()
            $output['Success'] = "true"
        ***
        catch ***
            $output['Error'] = $_.exception.Message
        ***
        return ConvertTo-Json $output
***
  "Error": "You cannot call a method on a null-valued expression."
***
Error: Azure PowerShell Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"

Our runner is running a container, that is ubuntu-latest and installs azure cli inside it and powershell.
Here is the container

FROM ubuntu:latest


RUN apt-get update && apt-get upgrade -y
RUN apt remove azure-cli -y && apt autoremove -y
RUN apt-get install ca-certificates curl apt-transport-https lsb-release gnupg wget software-properties-common -y
RUN wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null
RUN echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ focal main" | tee /etc/apt/sources.list.d/azure-cli.list
RUN cat /etc/apt/sources.list.d/azure-cli.list
RUN apt-get update
RUN apt-get install azure-cli powershell -y
RUN pwsh -Command Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
RUN pwsh -Command Install-Module Az.DataFactory  -Scope CurrentUser -Repository PSGallery -Force

I had to do this because when using azure@login, the command would fail

Run azure/login@v1
  with:
    creds: ***
    enable-AzPSSession: true
    environment: azurecloud
    allow-no-subscriptions: false
    audience: api://AzureADTokenExchange
  env:
    resourceGroupName: a...
    dataFactoryName: a...
    CLIENTID: ***
    CLIENTSECRET: ***
    SUBSCRIPTIONID: ***
    TENANTID: ***
    AZURE_CREDENTIALS: ***
    ***
    ***
    ***
    ***
  ***
/usr/local/bin/docker exec  6ed3b46f9cf105cb26a730c4f8342df9b3642c66020ef5ad3d97fe117419d26d sh -c "cat /etc/*release | grep ^ID"
Error: Az CLI Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows

@hedglenrm
Copy link
Author

hedglenrm commented Dec 6, 2021

Here is the full yml file:

name: Testbuild
on:
  push:
    branches:
      - develop


env:
  resourceGroupName: test-rg
  dataFactoryName: test-adf

jobs:
  deploy:
    runs-on: [self-hosted, azure]
    container: harbor.tools.dcsg.com/data-engineering/ubuntu:latest
    steps:
      - name: Code checkout
        uses: actions/checkout@v2
      - name: Get Azure credentials from Vault
        id: sectest
        uses: hashicorp/[email protected]
        with:
          url: https://vault.tools.dcsg.com
          method: approle
          roleId: ${{ secrets.VAULT_ROLE_ID }}
          secretId: ${{ secrets.VAULT_SECRET_ID }}
          secrets: |
              /path/to/credentialclientId;
              /path/to/credential clientSecret;
              /path/to/credential subscriptionId;
              /path/to/credential tenantId;
      - name: Azure Login
        uses: azure/login@v1
        env: 
          AZURE_CREDENTIALS: "${{ toJson(steps.secrets.outputs) }}"
        with:
          creds: ${{ env.AZURE_CREDENTIALS }}
          enable-AzPSSession: true

      - name: Export ARM Template
        id: export
        uses: Azure/[email protected]
        # with:
        #   path: <data-factory-dir> # replace by the folder that contains the Data Factory resources and the package.json
      
      - name: Deploy resources
        uses: Azure/[email protected]
        with:
          resourceGroupName: ${{ env.resourceGroupName }}
          dataFactoryName: ${{ env.dataFactoryName }}
          armTemplateFile: '${{steps.export.outputs.arm-template-directory}}/ARMTemplateForFactory.json'
          armTemplateParametersFile: '${{steps.export.outputs.arm-template-directory}}/ARMTemplateParametersForFactory.json'
          # additionalParameters: 'key1=value key2=value keyN=value' [optional]

      - name: Publish artifact
        uses: actions/upload-artifact@v2
        with:
          name: data-factory-package
          path: ${{ steps.export.outputs.arm-template-directory }}
          if-no-files-found: error


@hedglenrm
Copy link
Author

Hello @fedeoliv we found the issue. I was not aware the ubuntu-latest had a bunch of prepackaged software installed. either way, we are using a container and installing azure cli and powershell inside it.

the action is spinning up another container, but the /runner path wasn't being mounted on the container, which is why we ran into the missing PrePostDeploymentScript.ps1.

jobs:
deploy:
runs-on: [self-hosted, azure]
container:
image: repo.dummy.com/data-engineering/adf:0.0.2
volumes:
- /runner:/runner

@fedeoliv
Copy link
Contributor

Humm I see @hedglenrm...there's a similar issue opened on the runner repo here that looks like the ${{ github.action_path }} points to a location in the host filesystem of the github runner host, which is not what you'd expect on a self-hosted container image.

Happy to see you found a workaround. Are you having any other issues with the ADF action?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants