Error code 2 on CI/CD of my HUGO site

I have issues with my CI/CD giving me error code 2, please help.

5:38:52 PM: Build ready to start
5:38:54 PM: build-image version: 53b83b6bede2920f236b25b6f5a95334320dc849
5:38:54 PM: build-image tag: v3.6.0
5:38:54 PM: buildbot version: e26592b49d9d56b21349effe1b8fab4d50845f11
5:38:54 PM: Fetching cached dependencies
5:38:54 PM: Failed to fetch cache, continuing with build
5:38:54 PM: Starting to prepare the repo for build
5:38:55 PM: No cached dependencies found. Cloning fresh repo
5:38:55 PM: git clone https://github.com/JobNmadu/rproject1
5:38:55 PM: Preparing Git Reference refs/heads/main
5:38:57 PM: Starting build script
5:38:57 PM: Installing dependencies
5:38:57 PM: Python version set to 2.7
5:38:58 PM: v12.18.0 is already installed.
5:38:59 PM: Now using node v12.18.0 (npm v6.14.4)
5:38:59 PM: Started restoring cached build plugins
5:38:59 PM: Finished restoring cached build plugins
5:38:59 PM: Attempting ruby version 2.7.1, read from environment
5:39:00 PM: Using ruby version 2.7.1
5:39:00 PM: Using PHP version 5.6
5:39:00 PM: Installing Hugo 0.77.0
5:39:01 PM: Hugo Static Site Generator v0.77.0-EF290125/extended linux/amd64 BuildDate: 2020-10-30T10:21:36Z
5:39:01 PM: Started restoring cached go cache
5:39:01 PM: Finished restoring cached go cache
5:39:01 PM: go version go1.14.4 linux/amd64
5:39:01 PM: go version go1.14.4 linux/amd64
5:39:01 PM: Installing missing commands
5:39:01 PM: Verify run directory
5:39:03 PM: ​
5:39:03 PM: ────────────────────────────────────────────────────────────────
5:39:03 PM: Netlify Build
5:39:03 PM: ────────────────────────────────────────────────────────────────
5:39:03 PM: ​
5:39:03 PM: ❯ Version
5:39:03 PM: @netlify/build 8.0.1
5:39:03 PM: ​
5:39:03 PM: ❯ Flags
5:39:03 PM: deployId: 5ff4961ce2b2a92ccdfc8071
5:39:03 PM: mode: buildbot
5:39:03 PM: ​
5:39:03 PM: ❯ Current directory
5:39:03 PM: /opt/build/repo
5:39:03 PM: ​
5:39:03 PM: ❯ Config file
5:39:03 PM: No config file was defined: using default values.
5:39:03 PM: ​
5:39:03 PM: ❯ Context
5:39:03 PM: production
5:39:03 PM: ​
5:39:03 PM: ────────────────────────────────────────────────────────────────
5:39:03 PM: 1. Build command from Netlify app
5:39:03 PM: ────────────────────────────────────────────────────────────────
5:39:03 PM: ​
5:39:03 PM: $ hugo
5:39:03 PM: Total in 0 ms
5:39:03 PM: Error: Unable to locate config file or config directory. Perhaps you need to create a new site.
5:39:03 PM: Run hugo help new for details.
5:39:03 PM: ​
5:39:03 PM: ────────────────────────────────────────────────────────────────
5:39:03 PM: β€œbuild.command” failed
5:39:03 PM: ────────────────────────────────────────────────────────────────
5:39:03 PM: ​
5:39:03 PM: Error message
5:39:03 PM: Command failed with exit code 255: hugo
5:39:03 PM: ​
5:39:03 PM: Error location
5:39:03 PM: In Build command from Netlify app:
5:39:03 PM: hugo
5:39:03 PM: ​
5:39:03 PM: Resolved config
5:39:03 PM: build:
5:39:03 PM: command: hugo
5:39:03 PM: commandOrigin: ui
5:39:03 PM: environment:
5:39:03 PM: - HUGO_VERSION
5:39:03 PM: publish: /opt/build/repo/public
5:39:03 PM: Caching artifacts
5:39:03 PM: Started saving build plugins
5:39:03 PM: Finished saving build plugins
5:39:03 PM: Started saving pip cache
5:39:03 PM: Finished saving pip cache
5:39:03 PM: Started saving emacs cask dependencies
5:39:03 PM: Finished saving emacs cask dependencies
5:39:03 PM: Started saving maven dependencies
5:39:03 PM: Finished saving maven dependencies
5:39:03 PM: Started saving boot dependencies
5:39:03 PM: Finished saving boot dependencies
5:39:03 PM: Started saving rust rustup cache
5:39:03 PM: Finished saving rust rustup cache
5:39:03 PM: Started saving rust cargo bin cache
5:39:03 PM: Finished saving rust cargo bin cache
5:39:03 PM: Started saving go dependencies
5:39:03 PM: Finished saving go dependencies
5:39:06 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:39:06 PM: Failing build: Failed to build site
5:39:06 PM: Failed during stage β€˜building site’: Build script returned non-zero exit code: 2
5:39:06 PM: Finished processing build request in 11.677625102s

Your repo doesn’t have any website to β€˜build’. It’s a pre-built website. In the Netlify UI, set base path to public, remove your build command and publish path.

Thanks very much, but the config.tomi file is not recognised, what might be the problem?

@JobNmadu, is it .tomi or .toml - because it should be the latter. just making sure you don’t have a typo.

Okay thanks. Until the subdomain request is approved, that’s when things would be clearer. Thanks once again.

Job N Nmadu. Partnerships for eternity, Partnership for 2030
Professor and Industrial Liaison Officer
Federal University of Technology, Minna, Nigeria(www.futminna.edu.ng)
&
President and Fellow, Nigerian Association of Agricultural Economists (www.naae.org.ng)

Department of Agricultural Economics and Farm Management
www.jobnmadu.blogspot.com
job_nmadu@futminna.edu.ng
job_nmadu@yahoo.co.uk

There’s no config.toml in your repo and since your website is already built, you don’t need one.

Hi, @JobNmadu. Your repo is public so I looked at the files in it here:

https://github.com/JobNmadu/rproject1

If you look at that page there is a subdirectory of the repo named β€œpublic”. This is the directory that hugo puts the built site into after the build is complete. There is no config.toml anywhere in the repo at this time.

Your repo contains the pre-built site. It does not contain the files required to build the site. It does contain the result after the build is complete.

Now compare that to this Hugo site repo (this is my site):

https://github.com/overlordofmu/hugo-of-mu.org

My repo above does have a config.toml and it does not contain the public directory.

My repo does contain the files required to build the site. It does not contain the result after the build is complete.

You and I have our repositories configured in β€œopposite” ways. Both ways do work.

You can publish the site with the repository configured the way you have it now. To do that there is no build command at all. Make the build command blank. Then make the publish directory setting β€œpublic”. This will cause Netlify to publish the contents of that direct without changing them at all.

By the way, I do recommend switching to the repo configuration I am using. I hope to explain why I recommend changing below.

I recommend changing because you are using hugo to build the site and your repo doesn’t contain the files hugo uses. If your local repo gets deleted, you cannot use hugo anymore without doing a bunch of unnecessary work.

Let’s say my computer breaks and I lose my local copy of the repo. If I get a new computer, I can just clone my repo and it is back to whatever my most recently pushed commit is. I have my markdown files and config.toml in my repo. After a new clone, I can start using hugo again on the new computer as soon as the clone is done.

Now, if your computer breaks and you need to make a new clone of your repo, your new clone doesn’t have the config.toml or markdown files. You have the public directory but hugo doesn’t use it. (In fact, it deletes all the files in public as the first step of building the site.)

You could still manually edit the HTML, CSS, and javascript but you cannot use hugo anymore because you don’t have config.toml or the markdown files. Those files only existed on the computer that broke.

If you wanted to use hugo again, you will need to recreate your markdown files and config.toml again. There is no automatic process to make the markdown and config.toml. You would manually need to recreate those files by working backwards from the contents of the subdirectory β€œpublic”. It probably wouldn’t be complex but it would probably be time consuming (and boring).

I hope this explains why the method I’m using is recommended. If you store the site source (and not the result) your repo then contains what hugo uses and you can get back to developing your site more quickly if a local computer or hard drive breaks.

You may have good reasons for doing it your way. I certainly don’t know all that is involved so please feel free to ignore this recommendation if you prefer the way you are using now.

If there are other questions, please let us know.

Thanks for this exposition. I am still wondering where things went wrong. I used @markginhrass guide on YouTube to create the repo and cloned it to my HDD. Thereafter the Hugo site was installed, built and pushed to the repo. The .toml file in there in my computer. I have being trying to do the CI/CD on Netley since late November and the problem has been what I shared before you advised that the build command should blank which now published the repo.

So what is the way forward?

Thanks.

Job N Nmadu. experience, expertise, efficiency: eternity in view!
Professor, Department of Agricultural Economics and Farm Management
Industrial Liaison Officer, Federal University of Technology, Minna, Nigeria (www.futminna.edu.ng)

www.jobnmadu.blogspot.com
job_nmadu@futminna.edu.ng
job_nmadu@yahoo.co.uk

If you want Netlify to build your website, you’d have to push your Hugo website’s source code and not the published website. The source code would be the folder in which you have your config.toml file locally. Once you publish that folder to a Git repo, you can connect it to Netlify and then, with build settings as:

base: /
command: hugo --minify
publish: public

you can get your website deployed, provided the source code of the website is not inside any sub-directory of your repo.

Okay thanks, I will get back to you on this.

Job N Nmadu. experience, expertise, efficiency: eternity in view!
Professor, Department of Agricultural Economics and Farm Management
Industrial Liaison Officer, Federal University of Technology, Minna, Nigeria (www.futminna.edu.ng)

www.jobnmadu.blogspot.com
job_nmadu@futminna.edu.ng
job_nmadu@yahoo.co.uk

After playing around with one thing or the other, the site seems to be running now.

Thanks.

Thanks so very much for your careful and patient guidance. At last jobnmadu.rbind.io is running but only the opening page, that is the about page, is visible. What of the posts page? Secondly, the site is still http://jobnmadu.rbind.io and has not been upgraded to https://jobnmadu.rbind.io. I was hoping that it would be done after 48hrs.

Thank you once more.

I don’t see the link for one on your home page. Mind providing one?

About the HTTPS, I can see that the HTTPS version is loading fine, however for some reason the non-HTTPS version isn’t redirecting to the HTTPS one. I don’t know why it’s happening.

Hi, @JobNmadu. It looks like you have Cloudflare as a proxy to the Netlify site. We have a support guide about why this block our SSL provisioning here (and how to fix it):

If there are any questions after reading the support guide above, please let us know.

Thanks for your patience with me. I was trying to follow your suggestion but again hooked. Through which option do I get to disable cloudflare? I have perused all the options the whole day without getting it.

Also, the actual problem is that there is a check on DNS configuration. See the picture below:

Hi, @JobNmadu. You are most welcome and no patience is required. We are always happy to answer questions about Netlify. :+1:

The setting to change isn’t at Netlify. It is a setting at Cloudflare as shown in that support guide I linked to. The screenshot below is from that guide and shows the setting:

Note, you can use Cloudflare the way you have it. However, if you do that, you must provide your own SSL certificate. If Netlify is going to provision the automatic Let’s Encrypt SSL certificates, then the setting above must be disabled. Please feel free to do whichever you decide is best.

Again, if there are any other questions, we are happy to answer. :smiley:

That is done!

What would be the next step?

Hi, @JobNmadu. I’m showing the record in the screenshot is for the www subdomain.

www.rbind.io.		300	IN	CNAME	rbind-io.netlify.com.

However, the subdomain you have added under the site settings is the jobnmadu subdomain here:

https://app.netlify.com/sites/jobnmadu/settings/domain#custom-domains

Those two need to match. So you can either change the subdomain in the Cloudflare DNS record to jobnmadu (not www) or you can change the subdomain in the site settings at Netlify to www. Either of those two solutions will work.

Once the change is made the β€œVerify DNS settings” button on that same site settings page should work and the SSL certificate should be enabled soon after (within about one minute).

Hi, @JobNmadu. I’m showing that this domain name (jobnmadu.rbind.io) isn’t pointing to Netlify when I test:

$ dig +noall +answer jobnmadu.rbind.io
jobnmadu.rbind.io.	299	IN	A	104.21.18.231
jobnmadu.rbind.io.	299	IN	A	172.67.183.224

Those two IP addresses are Cloudflare IP addresses:

$ whois 104.21.18.231 | grep "OrgName"
OrgName:        Cloudflare, Inc.
$ whois 172.67.183.224 | grep "OrgName"
OrgName:        Cloudflare, Inc.

With that configuration, you must provide your own SSL certificate because we cannot provision one. Alternatively, if you stop using Cloudflare as a proxy in front of Netlify, we could then provision an automatic SSL certificate using Let’s Encrypt.

If there are other questions about this, please let us know.

Was expecting your guide, as I requested earlier, I will like to remain with netlify, how can I achieve that?