Changing Hugo version on Netlify build

2019-01-26 19:35发布

问题:

There is a new (0.32 at this time) version of Hugo that has just been released.

It was asked in the community how to handle this situation to test out the new version on a Netlify build.

What is the recommended course of action for Netlify users?

回答1:

If you do not setup a variable HUGO_VERSION on Netlify it defaults to version 0.17 of HUGO.

Simple Setup:

To target your builds Netlify has a custom variables field in the online console for your site. This will be enough for simple sites that need to target all workflow builds.

Workflow Setup

Netlify allows for a config file (netlify.toml) at the root of your build package path that will tell it what configurations to use and will overwrite any build environment variables you setup in the simple example above.

netlify.toml example for Hugo

    [build]
      publish = "public"
      command = "hugo"
    # build a preview of the site [hugo --buildFuture]
    [context.deploy-preview]
      command = "hugo --buildFuture"
    # The default version you use for production if you don't use context
    [build.environment]
      HUGO_VERSION = "0.29"
    # The version you use for production
    [context.production.environment]
      HUGO_VERSION = "0.29"
    # you can lock a version of hugo for a deploy preview
    [context.deploy-preview.environment]
      HUGO_VERSION = "0.32"
    # you can lock a version of hugo for a branch-deploy (other than previews)
    [context.branch-deploy.environment]
      HUGO_VERSION = "0.32"

Things to note:

  • Have different versions for a branch deploy for testing a new version of Hugo
  • Also target other environment variables that Netlify allows like NODE_VERSION
  • Setup custom environment variables to target builds explained in this writeup that can be accessed from within your Hugo templates!
  • Read about deploy contexts for Netlify Here


标签: hugo netlify