Home
Support Forums

First build on created sites has error 128

Hi, we are working on a custom CMS and while introducing automatic creation of sites, we encountered that after the site is created a build is automatically triggered. The problem we have is that the first build always fails with:

"error_message":"Failed during stage 'preparing repo': error checking for ref: Warning: Permanently added 'github.com' (RSA) to the list of known hosts.\r\ngit@github.com: Permission denied (publickey).\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n: exit status 128",

All subsequent builds pass without a problem, but we don’t like that our first build fails, as our clients are able to see that failed deployment and will wonder why that happened.

We are creating the sites via Netlify’s API (using Netlify’s js-client), and prior to the site creation we create a repository with Github’s API.

Is there a way or some configuration missing in order to make that first build pass?

Deploy log:

{
      "id":"6193e1e52870c04310a67bf3",
      "site_id":"b7697821-daf3-4d43-9829-dda57150b70f",
      "build_id":"6193e1e52870c04310a67bf1",
      "state":"ready",
      "name":"sandbox-remarkable-penguin-6193e1bd5187227a60484e93",
      "url":"http://sandbox-remarkable-penguin-6193e1bd5187227a60484e93.netlify.app",
      "ssl_url":"https://sandbox-remarkable-penguin-6193e1bd5187227a60484e93.netlify.app",
      "admin_url":"https://app.netlify.com/sites/sandbox-remarkable-penguin-6193e1bd5187227a60484e93",
      "deploy_url":"http://6193e1e52870c04310a67bf3--sandbox-remarkable-penguin-6193e1bd5187227a60484e93.netlify.app",
      "deploy_ssl_url":"https://6193e1e52870c04310a67bf3--sandbox-remarkable-penguin-6193e1bd5187227a60484e93.netlify.app",
      "created_at":"2021-11-16T16:52:53.741Z",
      "updated_at":"2021-11-17T10:54:25.623Z",
      "user_id":"5b1edaa0dd6a543272c20cd3",
      "error_message":null,
      "required":[
         
      ],
      "required_functions":[
         
      ],
      "commit_ref":null,
      "review_id":null,
      "branch":"main",
      "commit_url":null,
      "skipped":null,
      "locked":null,
      "log_access_attributes":{
         "type":"firebase",
         "url":"https://netlify-builds6.firebaseio.com/builds/6193e1e52870c04310a67bf1/log",
         "endpoint":"https://netlify-builds6.firebaseio.com",
         "path":"/builds/6193e1e52870c04310a67bf1/log",
         "token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ2IjowLCJpYXQiOjE2MzcxNTQwMzksImQiOnsidWlkIjoiIn19.EkxYBASCKi_olqu7OzGT8aWl6piEePSB0e6JD_CgePE"
      },
      "title":null,
      "review_url":null,
      "published_at":"2021-11-16T16:55:30.111Z",
      "context":"production",
      "deploy_time":154,
      "available_functions":[
         
      ],
      "screenshot_url":null,
      "site_capabilities":{
         "title":"Netlify Team Plus",
         "asset_acceleration":true,
         "form_processing":true,
         "cdn_propagation":"partial",
         "build_node_pool":"buildbot-external-ssd",
         "domain_aliases":true,
         "secure_site":true,
         "prerendering":true,
         "proxying":true,
         "ssl":"custom",
         "rate_cents":0,
         "yearly_rate_cents":0,
         "ipv6_domain":"cdn.makerloop.com",
         "branch_deploy":true,
         "managed_dns":true,
         "geo_ip":true,
         "split_testing":true,
         "id":"nf_team_pro",
         "cdn_tier":"reg"
      },
      "committer":null,
      "skipped_log":null,
      "manual_deploy":false,
      "file_tracking_optimization":true,
      "plugin_state":"none",
      "has_edge_handlers":false,
      "links":{
         "permalink":"https://6193e1e52870c04310a67bf3--sandbox-remarkable-penguin-6193e1bd5187227a60484e93.netlify.app",
         "alias":"https://sandbox-remarkable-penguin-6193e1bd5187227a60484e93.netlify.app",
         "branch":null
      },
      "framework":"unknown",
      "entry_path":null,
      "views_count":null
   },
   {
      "id":"6193e1c23000ce423f29085a",
      "site_id":"REDACTED",
      "build_id":"6193e1c23000ce423f290858",
      "state":"error",
      "name":"sandbox-remarkable-penguin-6193e1bd5187227a60484e93",
      "url":"http://sandbox-remarkable-penguin-6193e1bd5187227a60484e93.netlify.app",
      "ssl_url":"https://sandbox-remarkable-penguin-6193e1bd5187227a60484e93.netlify.app",
      "admin_url":"https://app.netlify.com/sites/sandbox-remarkable-penguin-6193e1bd5187227a60484e93",
      "deploy_url":"http://6193e1c23000ce423f29085a--sandbox-remarkable-penguin-6193e1bd5187227a60484e93.netlify.app",
      "deploy_ssl_url":"https://6193e1c23000ce423f29085a--sandbox-remarkable-penguin-6193e1bd5187227a60484e93.netlify.app",
      "created_at":"2021-11-16T16:52:18.409Z",
      "updated_at":"2021-11-16T16:52:21.374Z",
      "user_id":"5b1edaa0dd6a543272c20cd3",
      "error_message":"Failed during stage 'preparing repo': error checking for ref: Warning: Permanently added 'github.com' (RSA) to the list of known hosts.\r\ngit@github.com: Permission denied (publickey).\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n: exit status 128",
      "required":[
         
      ],
      "required_functions":null,
      "commit_ref":null,
      "review_id":null,
      "branch":"main",
      "commit_url":null,
      "skipped":null,
      "locked":null,
      "log_access_attributes":{
         "type":"firebase",
         "url":"https://netlify-builds5.firebaseio.com/builds/6193e1c23000ce423f290858/log",
         "endpoint":"https://netlify-builds5.firebaseio.com",
         "path":"/builds/6193e1c23000ce423f290858/log",
         "token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ2IjowLCJpYXQiOjE2MzcxNTQwMzksImQiOnsidWlkIjoiIn19.Myx4AdSykOrU3a3oZRbVLpWyGgjxPfkKdTLgnDj_vjs"
      },
      "title":null,
      "review_url":null,
      "published_at":null,
      "context":"production",
      "deploy_time":null,
      "available_functions":[
         
      ],
      "screenshot_url":null,
      "site_capabilities":{
         "title":"Netlify Team Plus",
         "asset_acceleration":true,
         "form_processing":true,
         "cdn_propagation":"partial",
         "build_node_pool":"buildbot-external-ssd",
         "domain_aliases":true,
         "secure_site":true,
         "prerendering":true,
         "proxying":true,
         "ssl":"custom",
         "rate_cents":0,
         "yearly_rate_cents":0,
         "ipv6_domain":"cdn.makerloop.com",
         "branch_deploy":true,
         "managed_dns":true,
         "geo_ip":true,
         "split_testing":true,
         "id":"nf_team_pro",
         "cdn_tier":"reg"
      },
      "committer":null,
      "skipped_log":null,
      "manual_deploy":false,
      "file_tracking_optimization":true,
      "plugin_state":"none",
      "has_edge_handlers":false,
      "links":{
         "permalink":"https://6193e1c23000ce423f29085a--sandbox-remarkable-penguin-6193e1bd5187227a60484e93.netlify.app",
         "alias":"https://sandbox-remarkable-penguin-6193e1bd5187227a60484e93.netlify.app",
         "branch":null
      },
      "framework":"not_fetched",
      "entry_path":null,
      "views_count":null
   }

I’m not sure what could be happening here. Does including a wait time between creating a repo and calling Netlify API help?

@hrishikesh we cannot add wait time, it has to happen all in the short Netlify Function time so that it doesn’t time out. Is there a way to disable it from creating a build once the site is created?

Unfortunately not, as that’s the behaviour I believe the major chunk would expect it to work.

Could you split the call in 2 different function calls? For example, you create the repo, get. response, then wait in your frontend or something and then call Netlify API.

Would that work?

Not really, all this has to happen within the same function call, it’s part of the UX and structure we’ve given to the API we are building. It’s fine if it’s not possible, we’d like to be able to avoid this initial build or at least avoid the error, but it’s ok.

Thanks

You can simply send a POST request to https://api.netlify.com/api/v1/sites/ without any body and that would create a new site without any deploy.

Would that work?

@hrishikesh without any body or without the gitRepository part of the body? We cannot send without a body because we need to configure some stuff for the sites during creation. I’ve already tried editing the gitRepository using the PATCH request (if I’m not mistaken) and that would throw errors from the API’s side.

I believe anything without the gitRepo should work.

Connecting the Git repo via the API might not probably work.

Yeah, we cannot do that, we need the connection be automatic. I believe it’s fine though, we’ll move away from this feature probably, so it’s not a problem anymore this.

Thank you!