Netlify中Jekyll的上下文变量

时间:2019-04-22 13:25:43

标签: jekyll netlify

Jekyll检测到构建,然后等待JEKYLL_ENV变量:https://jekyllrb.com/docs/configuration/environments/

Netlify设置CONTEXT变量:https://www.netlify.com/docs/continuous-deployment/?_ga=2.28134843.62454114.1555938051-984068889.1555938051#environment-variables

结果Jekyll没有看到我的建物

3 个答案:

答案 0 :(得分:0)

Netlify的CONTEXT变量不能与Jekyll的JEKYLL_ENV相同。因此,您可能想单独使用netlify.toml来设置JEKYLL_ENV?这样的事情可能会起作用:

# this will be the default for every branch other than the production branch
[build.environment]
  JEKYLL_ENV="development"
# only for production branch, override to production
[context.production.environment]
  JEKYLL_ENV="production"

答案 1 :(得分:0)

我成功地测试了三种不同的设置JEKYLL_ENV环境变量的方法,然后可以在Liquid模板中以jekyll.environment的形式对其进行访问:

  1. netlify.toml:直接在构建命令中设置环境变量

    # global context
    [build]
      publish = "_site/"
      command = "JEKYLL_ENV=\"netlify\" jekyll build"
    
  2. netlify.toml:设置构建环境

    # global context
    [build]
      publish = "_site/"
      command = "jekyll build"
      environment = { JEKYLL_ENV = "netlify" }
    
  3. netlify.toml:运行自定义构建脚本

    # global context
    [build]
      publish = "_site/"
      command = "sh netlify.sh"
    

    netlify.sh:在构建命令中设置环境变量

    JEKYLL_ENV="netlify" jekyll build
    

答案 2 :(得分:0)

我遇到了同样的问题,并通过在Netlify设置页面的环境变量中添加JEKYLL_ENV对其进行了排序。无需添加toml文件。