Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
parameters:
# unique name of the job
job_name: build_package
# friendly name of the job
display_name: SPFx production build & packaging
# agent pool details (default: MSFT hosted Ubuntu)
pool: Default
# vmImage: ubuntu-latest
# relative path to the project root if not in root of repo
working_directory: '.'
# package manager
package_manager: 'npm'
# node version
node_version: '10.x'
jobs:
- job: ${{ parameters.job_name }}
displayName: ${{ parameters.display_name }}
pool: ${{ parameters.pool }}
steps:
##########################################
## specify which node version to use
##########################################
- task: UseNode@1
displayName: Set to Node.js ${{ parameters.node_version }}
inputs:
version: ${{ parameters.node_version }}
condition: ne('${{ parameters.node_version }}', '')
##########################################
## install PNPM if that is desired package manager
##########################################
- script: echo "${{ parameters.working_directory }}"
- script: sudo npm install --global pnpm
displayName: Install PNPM
condition: eq('${{ parameters.package_manager }}', 'pnpm')
##########################################
## install gulp
##########################################
- script: npm install --global gulp
displayName: Install gulp
##########################################
## install dependencies using specified
## package manager
##########################################
- script: npm ci
displayName: Install dependencies (with NPM)
workingDirectory: ${{ parameters.working_directory }}
condition: eq('${{ parameters.package_manager }}', 'npm')
- script: yarn install --frozen-lockfile
displayName: Install dependencies (with Yarn)
workingDirectory: ${{ parameters.working_directory }}
condition: eq('${{ parameters.package_manager }}', 'yarn')
- script: pnpm install --shamefully-hoist --frozen-lockfile
displayName: Install dependencies (with PNPM)
workingDirectory: ${{ parameters.working_directory }}
condition: eq('${{ parameters.package_manager }}', 'pnpm')
##########################################
## execute: gulp build
##########################################
- task: Gulp@1
displayName: SPFx build
inputs:
gulpFile: ${{ parameters.working_directory }}/gulpfile.js
workingDirectory: ${{ parameters.working_directory }}
targets: build
##########################################
## execute: gulp bundle --ship
##########################################
- task: Gulp@1
displayName: SPFx bundle (production)
inputs:
gulpFile: ${{ parameters.working_directory }}/gulpfile.js
workingDirectory: ${{ parameters.working_directory }}
targets: bundle
arguments: --ship
##########################################
## execute: gulp package-solution --ship
##########################################
- task: Gulp@1
displayName: SPFx package solution (production)
inputs:
gulpFile: ${{ parameters.working_directory }}/gulpfile.js
workingDirectory: ${{ parameters.working_directory }}
targets: package-solution
arguments: --ship
##########################################
## Copy the artifacts to the artifacts staging directory
##########################################
- task: CopyFiles@2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)/drop'
inputs:
Contents: |
sharepoint/solution/*.sppkg
*.ps1
*.pfx
TargetFolder: '$(build.artifactstagingdirectory)/drop'
##########################################
## Publosh the artifacts to the drop folder
##########################################
#publish artifacts
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)/drop'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment