HodorNV / ALOps

ALOps
56 stars 24 forks source link

Question: how to use ALOpsAppClean? #311

Closed lvanvugt closed 3 years ago

lvanvugt commented 3 years ago

I could not find an example that shows me how to use ALOpsAppClean. More specifically:

waldo1001 commented 3 years ago

Hi Luc,

to answer your questions.

This should be done after the wait.

We could also foresee something in the docker create task - but that would over-complicate the step a bit, don't you think? What if you already created an image (dockercreate) and another pipeline on the same build agent should need it WITH MS apps? We can't just put all exceptions in params .. that's why we built building blocks as steps ;-). I hope that makes sense.

The sync-mode is the default sync from business central cmdlet "Sync-NAVApp". More info here: https://docs.microsoft.com/en-us/powershell/module/microsoft.dynamics.nav.apps.management/sync-navapp?view=businesscentral-ps-16

We also set it default to "Add", because it needs to be a conscious step to clean data (remember people can also put this step in a release pipeline for any reason).

lvanvugt commented 3 years ago

Thanx, @waldo1001, can agree, although not having it in the ALOpsDockerCreate costs approx. 1 minute extra in the pipeline.

One thing: as said "I want to use this to uninstall all MS apps (except of course the Application) before I run my pipeline", but when I setup the task as follows it also removes the Application (apps).

 - task: ALOpsAppClean@1
    inputs:
      usedocker: true
      includemicrosoftapps: true

What am I doing wrong?

waldo1001 commented 3 years ago

Hm, you are right - BaseApp is also a Microsoft app - so that one is included in the remove. This step is originally introduced for pipelines with a customized baseapp.. . So pretty useless for you in this case.

Not much we can do about this. We don't want to end up with steps with +30 parameters to accommodate every single exception people want with in their pipelines.. . We need to keep it simple.

But .. there is another option ;-).

We have a DockerExec step, that makes it possible for exceptions like this. Where you can execute any powershell within the container. So, if you would do this:

  - task: ALOpsDockerExec@1
    inputs:
      inline_script: |
        Get-NAVAppInfo -ServerInstance BC -tenant default -tenantspecificproperties | 
          where isinstalled -eq $true | 
            Where Publisher -eq Microsoft | 
              where {$_.Name -ne 'Base Application' -and $_.Name -ne 'System Application' -and $_.Name -ne 'Application'}  | 
                uninstall-navapp -tenant default -force

it will remove all apps except the base app and such. I think it's pretty readable.. .

Another option would be to build your own docker images yourself (not by the dockercreate step, but completely yourself with the docker-commands) and reference them from the pipeline. This way, you would be able to have faster pipelines - but it's a docker-think, not really an ALOps thing ;-).

Can I ask - why is this necessary? It's the first time we get this question ..

lvanvugt commented 3 years ago

Thanx for the suggestion (and ALOpsAppClean indeed is then useless for me).

To your question: wanting to run the standards tests I found out that some MS extensions do screw up the test results of BaseApp tests. So, I need to get these extensions uninstalled before I run the tests.

waldo1001 commented 3 years ago

Ok, now I understand - it's what I expected ;-).

The DockerExec brings lots of flexibility .. but obviously, we try to avoid using it as much as possible as the goal is to use no powershell at all ;-).

lvanvugt commented 3 years ago

Added the suggest task, but getting error when wanting to run the pipeline. Not sure what is failing.

Encountered error(s) while parsing pipeline YAML:
/TestFixtureInitializer/Azure Pipelines/azure-pipelines-INVOICING - onprem.yml: (Line: 38, Col: 7, Idx: 956) - (Line: 38, Col: 7, Idx: 956): While parsing a block mapping, did not find expected key.
waldo1001 commented 3 years ago

yml syntax ...

I'll have to see the entire yaml...

lvanvugt commented 3 years ago

Here you go:

name: $(Build.BuildId)

trigger:
 branches:
   include:
     - master/TestFixtureInitializer

variables:
- group: 'PipelineVariables'

pool: TestAutomationExamples

jobs:
- job: default
  timeoutInMinutes: 600
  pool: TestAutomationExamples

  steps:
  - checkout: self
    clean: true 

  - task: ALOpsDockerCreate@1
    displayName: 'ALOPS - Create Docker Image' # It will reuse the image if already exists, or build one if it doesn't.
    inputs:
      forcecreateimage: $(forceCreateImage)
      licensefile: '$(LuxBeheerBcDevLicense)'

  - task: ALOpsDockerStart@1
    displayName: 'ALOPS - Start Docker Container' # No need to provide any details - it will get the details from previous step

  - task: ALOpsDockerWait@1
    displayName: 'ALOPS - Wait for Docker Container to start'
    inputs:
      search_string: 'Ready for connections!'

  - task: ALOpsDockerExec@1
    displayName: 'ALOPS - uninstall MS apps (but leave Application apps)'
      inputs:
        inline_script: |
          Get-NAVAppInfo -ServerInstance BC -tenant default -tenantspecificproperties | 
            where isinstalled -eq $true | 
              Where Publisher -eq Microsoft | 
                where {$_.Name -ne 'Base Application' -and $_.Name -ne 'System Application' -and $_.Name -ne 'Application'}  | 
                  uninstall-navapp -tenant default -force

  - task: ALOpsAppPublish@1
    displayName: 'ALOPS - Install AL TestTool' # install necessary dependent apps for testability
    inputs:
      usedocker: true
      installaltesttool: true
      skip_verification: true
      install_al_app_names: |
        Any
        Library Assert
        Library Variable Storage
        System Application Test Library
        Tests-TestLibraries
        Tests-Invoicing
        Test Runner

  - task: ALOpsAppCompiler@1
    displayName: 'ALOPS - Compile Extension: App'
    inputs:
      usedocker: true
      nav_app_version: '1.0.[yyyyWW].*'
      targetproject: 'TestFixtureInitializer/app/app.json'
      app_file_suffix: '_APP'                                 # A trick to uniquely identify the APP (from the TEST-app)

  - task: ALOpsAppPublish@1
    displayName: 'ALOPS - Publish Extension'
    inputs:
      usedocker: true
      nav_artifact_app_filter: '*.app'
      skip_verification: true

  - task: ALOpsAppCompiler@1
    displayName: 'ALOPS - Compile Extension: Test-App'
    inputs:
      usedocker: true
      nav_app_version: '1.0.[yyyyWW].*'
      targetproject: 'TestFixtureInitializer/test/app.json'
      failed_on_warnings: true    
      app_file_suffix: '_TEST'                                 # A trick to uniquely identify the Test-App (from the App)

  - task: ALOpsAppPublish@1
    displayName: 'ALOPS - Publish Extension'
    inputs:
      usedocker: true
      nav_artifact_app_filter: '*.app'
      skip_verification: true   

  - task: ALOpsAppTest@1
    displayName: 'ALOPS - Run TestSuite'
    inputs:
      usedocker: true
      import_action: "Skip"
      import_testtoolkit: false
      testpage: '130455'
      testsuite: 'INVOICING'
      failed_test_action: 'Ignore'
    continueOnError: true
    timeoutInMinutes: 30

  - task: PublishTestResults@2
    displayName: 'Publish Test Results **/TestResults.xml'
    inputs:
      testResultsFormat: XUnit
      testResultsFiles: '**/TestResults.xml'
      failTaskOnFailedTests: true
      testRunTitle: 'BC Test Results: $(Build.BuildId)'

  - task: ALOpsDockerRemove@1
    displayName: 'ALOPS - Remove Docker Container'
    enabled: true
    condition: always()
    inputs:
      createsqlbackup: '$(createSqlBackup)'
waldo1001 commented 3 years ago

image

indentation is wrong...

you also see it when editing the pipeline: image

;-)

lvanvugt commented 3 years ago

Damn, thought I had checked that. Thanx.