skip to Main Content

I have added variables in azure pipeline but its not attached in copy files in last step of copy
Below yml script:

trigger:
- branch name

pool:
  vmImage: 'windows-latest'

variables:
  projectFolder: '.'
steps:
- task: NodeTool@0
  displayName: 'Use Node 14.17.0'
  inputs:
    versionSpec: 14.17.0

- script: 'npm i'
  displayName: 'Install Dependencies'

- task: DownloadSecureFile@1
  inputs:
    secureFile: 'Constants.json'
- task: CopyFiles@2
  inputs:
    SourceFolder: '$(Agent.TempDirectory)'
    Contents: '**/*Constants.json'
    TargetFolder: '$(projectFolder)'

- script: 'npm run build'
  displayName: 'build app'

- task: CopyFiles@2
  displayName: 'Copy Files'
  inputs:
    SourceFolder: build
    TargetFolder: '$(Build.ArtifactStagingDirectory)'

- task: ArchiveFiles@2
  displayName: 'Archive $(Build.ArtifactStagingDirectory)'
  inputs:
    rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'

how to add download file in build zip.

2

Answers


  1. You need to modify the Yaml script so it includes the downloaded file in the build artifact.

    Try this code:

    trigger:
    - branch name
    
    pool:
      vmImage: 'windows-latest'
    
    variables:
      projectFolder: '.'
    
    steps:
    - task: NodeTool@0
      displayName: 'Use Node 14.17.0'
      inputs:
        versionSpec: 14.17.0
    
    - script: 'npm i'
      displayName: 'Install Dependencies'
    
    - task: DownloadSecureFile@1
      inputs:
        secureFile: 'Constants.json'
        
    - task: CopyFiles@2
      inputs:
        SourceFolder: '$(Agent.TempDirectory)'
        Contents: '**/Constants.json'
        TargetFolder: '$(projectFolder)'
    
    - script: 'npm run build'
      displayName: 'build app'
    
    - task: CopyFiles@2
      displayName: 'Copy Files'
      inputs:
        SourceFolder: build
        TargetFolder: '$(Build.ArtifactStagingDirectory)'
    
    # Include downloaded file in the build artifact
    - task: CopyFiles@2
      displayName: 'Include Constants.json in Artifact'
      inputs:
        SourceFolder: '$(projectFolder)' # Source folder where Constants.json is located
        Contents: 'Constants.json'
        TargetFolder: '$(Build.ArtifactStagingDirectory)'
    
    - task: ArchiveFiles@2
      displayName: 'Archive $(Build.ArtifactStagingDirectory)'
      inputs:
        rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
    
    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifact: drop'
    
    Login or Signup to reply.
  2. In your last CopyFiles@2 task, you copy files from build folder, which actually is $(Build.SourcesDirectory)build. So if you want Constants.json to be added to the .zip file, you need to copy it into $(Build.SourcesDirectory)build.

    In the first CopyFiles@2 task, you copy Constants.json to $(projectFolder). I’m not sure about the actual value of $(projectFolder). According to the current information, it should be $(Build.SourcesDirectory)build.

    Try the scripts below and check if it helps.

    trigger:
    - branch name
    
    pool:
      vmImage: 'windows-latest'
    
    variables:
      projectFolder: 'build'
    
    steps:
    - task: NodeTool@0
      displayName: 'Use Node 14.17.0'
      inputs:
        versionSpec: 14.17.0
    
    - script: 'npm i'
      displayName: 'Install Dependencies'
    
    - task: DownloadSecureFile@1
      inputs:
        secureFile: 'Constants.json'
    - task: CopyFiles@2
      inputs:
        SourceFolder: '$(Agent.TempDirectory)'
        Contents: 'Constants.json'
        TargetFolder: '$(Build.SourcesDirectory)$(projectFolder)'
    
    - script: 'npm run build'
      displayName: 'build app'
    
    - task: CopyFiles@2
      displayName: 'Copy Files'
      inputs:
        SourceFolder: build
        TargetFolder: '$(Build.ArtifactStagingDirectory)'
    
    - task: ArchiveFiles@2
      displayName: 'Archive $(Build.ArtifactStagingDirectory)'
      inputs:
        rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
        includeRootFolder: false
        archiveType: 'zip'
        archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
        replaceExistingArchive: true
    
    
    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifact: drop'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search