In this tutorial, you will set up CI/CD between Cloud Functions and SourceCraft. To make this work, you will create a repository, set up function deployment, and check the result.
If you no longer need the resources you created, delete them.
Required paid resources
The infrastructure support cost includes fees for function invocation count, computing resources allocated for the function, and outbound traffic (see Cloud Functions pricing).
Create a service account and authorized key
SourceCraft will use this service account to create a function and its versions.
Create a service account
Management console
CLI
API
In the management console, select Identity and Access Management from the list of services.
Click Create service account.
Enter the service account name: functions-cicd-sa.
Click Add role and select the functions.adminrole.
Click Create.
Create a service account named functions-cicd-sa:
yc iam service-account create --name functions-cicd-sa
In the management console, select Identity and Access Management from the list of services.
Select the functions-cicd-sa service account.
In the top panel, click Create new key and select Create authorized key.
Select the encryption algorithm.
Click Create.
Click Download file with keys. Make sure the file is saved on the computer. You will need its contents to create a secret. You will not be able to view the public key in the management console.
Run this command:
yc iam key create --service-account-name sa-function -o functions-cicd-sa_key_file.json
If successful, the authorized key data will be written to the functions-cicd-sa_key_file.json file. Here is an example:
{"id":"ajek6nubd5g3********","service_account_id":"ajelprpohp7r********","created_at":"2025-05-28T16:17:17.721526532Z","key_algorithm":"RSA_2048","public_key":"-----BEGIN PUBLIC KEY-----\nMI...QAB\n-----END PUBLIC KEY-----\n","private_key":"PLEASE DO NOT REMOVE THIS LINE! Yandex.Cloud SA Key ID \u003cajek6nubd5g3********\u003e\n-----BEGIN PRIVATE KEY-----\nMI...WdQ=\n-----END PRIVATE KEY-----\n"}
To create an authorized access key, use the create REST API method for the Key resource or the Key/Create gRPC API call.
Create a repository
The repository will store the function parameters and code, and the CI/CD process settings.
In the window that opens, select Blank repository.
Under Your new repository details:
In the Owner field, select the organization to create the repository in.
In the Name field, specify a name for the repository.
The name must be unique within the organization. The name may contain the following ASCII characters: lowercase and uppercase Latin letters, numbers, commas, hyphens, and underscores.
The address to access the repository at is displayed below the name.
Optionally, in the Description field, enter a description for the repository.
Click Create repository.
Create a secret in the repository
The secret will store the encrypted authorized service account key for access to the function.
Repeat these steps to create a file named .sourcecraft/ci.yaml. Paste the code below into it stating the ID of the folder you want to create your function in:
on:push:-workflows:cicdfilter:branches: [ main ]
workflows:cicd:tasks:-name:deploy-latestenv:TMP_PATH:./tmpYC_AUTHORIZED_KEY_JSON:${{secrets.<secret_name>}}YC_FOLDER_ID:<folder_ID>YC_FUNCTION_NAME:cicd-testYC_FUNCTION_RUNTIME:nodejs22YC_FUNCTION_ENTRYPOINT:index.handlerYC_FUNCTION_MEMORY:128mcubes:-name:install-and-configure-ycscript:-curl-o./yc-install.sh-Lhttps://storage.yandexcloud.net/yandexcloud-yc/install.sh-chmod+x./yc-install.sh&&./yc-install.sh-i/tmp/yc-n&&mv/tmp/yc/bin/yc/usr/bin/yc-echo"$YC_AUTHORIZED_KEY_JSON">key.json-ycconfigprofilecreatesa-profile-ycconfigsetservice-account-keykey.json-ycconfigsetformatjson-ycconfigsetfolder-id$YC_FOLDER_ID-name:check-and-create-functionscript:-|
echo "Checking if function exists..."
if ! yc serverless function get --name=$YC_FUNCTION_NAME; then
echo "Function does not exist. Creating new function..."
yc serverless function create --name=$YC_FUNCTION_NAME
else
echo "Function already exists. Proceeding to version deployment..."
fi
-name:deploy-function-versionscript:-mkdir-p$TMP_PATH-cp./*.js*$TMP_PATH-echo"Deploying new function version..."-|
yc serverless function version create \
--function-name=$YC_FUNCTION_NAME \
--runtime $YC_FUNCTION_RUNTIME \
--entrypoint $YC_FUNCTION_ENTRYPOINT \
--memory $YC_FUNCTION_MEMORY \
--execution-timeout 5s \
--source-path $TMP_PATH
Where:
YC_FOLDER_ID: ID of the folder to host your function.
YC_FUNCTION_NAME: Function name.
YC_FUNCTION_RUNTIME: Runtime environment.
YC_FUNCTION_ENTRYPOINT: Entry point.
YC_FUNCTION_MEMORY: Amount of RAM.
In the top-right corner, click Commit changes.
Commit:
Enter a message about the changes.
Under Commit branch, select Commit directly to the branch: main.
Under After commit action, select Just commit.
Click Commit and back to Read mode.
Check the CI/CD process
Make sure the CI/CD process completes successfully.
Get a list of functions in the folder specified in .sourcecraft/ci.yaml:
yc serverless function list
Result:
+----------------------+-----------+----------------------+--------+
| ID | NAME | FOLDER ID | STATUS |
+----------------------+-----------+----------------------+--------+
| b097d9ous3ge******** | cicd-test | aoek49ghmknn******** | ACTIVE |
+----------------------+-----------+----------------------+--------+
The command output should now contain the function named cicd-test.
Get a list of versions of the cicd-test function:
yc serverless function version list --function-id <function_ID>
Result:
+----------------------+----------------------+----------+---------------+---------+---------------------+
| ID | FUNCTION ID | RUNTIME | ENTRYPOINT | TAGS | CREATED AT |
+----------------------+----------------------+----------+---------------+---------+---------------------+
| b097d9ousd36******** | b097d9ous3ge******** | nodejs22 | index.handler | $latest | 2025-05-28 05:05:12 |
+----------------------+----------------------+----------+---------------+---------+---------------------+
The command output should now contain the function's version with the same timestamp as the CI/CD process execution.