---
name: codeengine-fun-create-repo
title: Creating function workloads with repository source code
description: You can create your function directly from source code that is located in a Git repository from the IBM Cloud&reg; Code Engine console or with the CLI.
last-updated: 2026-07-01
---

> ## Documentation Index
> The table of contents for this documentation set is at https://cloud.ibm.com/docs/codeengine?format=markdown
> The index for all IBM Cloud docs is at: https://cloud.ibm.com/docs/llms.txt
> Use these files to discover more information as needed.

# Creating function workloads with repository source code
{: #fun-create-repo}


You can create your function directly from source code that is located in a Git repository from the IBM Cloud&reg; Code Engine console or with the CLI.
{: shortdesc}

A code bundle is a collection of files that represents your function code. This code bundle is injected into the runtime container. Your code bundle is created by Code Engine and is stored in container registry or inline with the function. A code bundle is not a Open Container Initiative (OCI) standard container image.

In this scenario, Code Engine builds a code bundle from your Git repository source, automatically uploads the code bundle to your container registry, and then creates your function to reference this built code bundle. You need to provide only a name for the function, the URL to the Git repository, and the runtime for the function. In this case, Code Engine manages the namespace for you. However, if you want to use a different container registry, then you must specify the code bundle and a registry secret for that container registry. 

For information about required permissions for accessing image registries, see [Setting up authorities for image registries](https://cloud.ibm.com/docs/codeengine?topic=codeengine-add-registry&format=markdown#authorities-registry).


## Creating function workloads with repository source code from the console
{: #fun-create-repo-console}


Create a function with source code from the console.
{: shortdesc} 

1. Open the [Code Engine](https://cloud.ibm.com/codeengine/overview){: external} console.
2. Select **Start creating**.
3. Select a project from the list of available projects. You can also [create a new one](https://cloud.ibm.com/docs/codeengine?topic=codeengine-manage-project&format=markdown#create-a-project). You must select a project to create a function.
4. Select **Function**.
5. Enter a name for the function; for example, `myfunction`. Use a name for your function that is unique within the project.
6. Select a **Runtime image** for your function code. For more information, see [Runtimes](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-runtime&format=markdown).
7. Select to **Build code bundle from source code**. When you select this option, your function is created from source code and stored in container registry.
8. Select a source repository, for example `https://github.com/IBM/CodeEngine`. If you choose to use the sample source, you do not need require credentials so you can select `None` for the **Code repo access**. You can optionally provide a branch name. If you do not provide a branch name and you leave the field empty, Code Engine automatically uses the default branch of the specified repository. Click **Next**.  
9. Select a strategy for your build and resources for your build. For more information about build options, see [Planning your build](https://cloud.ibm.com/docs/codeengine?topic=codeengine-plan-build&format=markdown). Click **Next**.
10. Select a container registry location, such as `IBM Registry Dallas` to specify where to store the image of your build output. If your registry is private, you must [set up access](https://cloud.ibm.com/docs/codeengine?topic=codeengine-add-registry&format=markdown) to it.
11. Provide registry information about where to store the image of your build output. Select an existing **Registry secret** or create a new one. If you are building your image to a Container Registry instance that is in your account, you can select `Code Engine managed secret` and let Code Engine create and manage the secret for you.
12. Select a namespace, name, and a tag for your image. If you are building your image to an IBM Cloud Container Registry instance that is in your account, you can select an existing namespace or let Code Engine create and manage the namespace for you. For additional help, click **Help me specify the code bundle**. For more information, see [Accessing container registries](https://cloud.ibm.com/docs/codeengine?topic=codeengine-add-registry&format=markdown).
13. Specify your resource information, including [CPU and memory combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-runtime&format=markdown#fun-supported-combo) and [Scale down delay](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-work&format=markdown#functions-scale). 
14. Optionally, specify a [custom domain](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-domainmapping&format=markdown) or [environment variables](https://cloud.ibm.com/docs/codeengine?topic=codeengine-envvar&format=markdown). You can add these options later.
15. Click **Create**.
16. After the function status changes to **Ready**, you can test the function. Click **Test function** and then click **Send request**. To open the function in a web page, click **Function URL**. 
17. You can also change your function code in the Editor window. When you redeploy your function, the code is stored inline.

You can invoke your function by clicking **Test function** and then **Send request**.


## Creating function workloads with repository source code with the CLI
{: #fun-create-repo-cli}

Use the **`function create`** command to both build a code bundle from your Git repository source, and create your function to reference this built code bundle. For a complete listing of options, see the [**`ibmcloud ce function create`**](https://cloud.ibm.com/docs/codeengine?topic=codeengine-cli&format=markdown#cli-function-create) command.


Before you begin

* Set up your [Code Engine CLI](https://cloud.ibm.com/docs/codeengine?topic=codeengine-install-cli&format=markdown) environment.
* [Create and work with a project](https://cloud.ibm.com/docs/codeengine?topic=codeengine-manage-project&format=markdown).


The following example **`function create`** command creates the `myfun` function, which references code that is located in `https://github.com/IBM/CodeEngine`. This command automatically builds the code bundle and uploads it to an IBM Cloud&reg; Container Registry namespace in your account. The function references this built code bundle. By specifying the `--build-context-dir` option, the build uses the source in the `helloworld-samples/function-codebundle-nodejs` directory.

```txt
ibmcloud ce function create --name myfun --runtime nodejs --build-source https://github.com/IBM/CodeEngine --build-context-dir /helloworld-samples/function-codebundle-nodejs
```
{: pre}

Example output

```txt
Preparing function 'myfun' for build push...
Creating function 'myfun'...
Submitting build run 'myfun-run-230111-111212718'...
Creating image 'icr.io/ce--abcde-glxo4kabcde/function-myfun:230111-1532-vwo4o'...
Waiting for build run to complete...
Build run status: 'Running'
Build run completed successfully.
Run 'ibmcloud ce buildrun get -n myfun-run-230111-111212718' to check the build run status.
Waiting for function 'myfun' to become ready...
Function 'myfun' is ready.
OK                                                
Run 'ibmcloud ce function get -n myfun' to see more details.

https://myfun.11a66hbi3rhz.us-south.codeengine.appdomain.cloud
```
{: screen}

Notice the output of the **`function create`** command provides information on the progression of the build run before the function is created. 
{: tip}

In this example, the built code bundle is uploaded to the `ce--abcde-4svg40kna19` namespace in Container Registry. 

The following table summarizes the options that are used with the **`function create`** command in this example. For more information about the command and its options, see the [**`ibmcloud ce function create`**](https://cloud.ibm.com/docs/codeengine?topic=codeengine-cli&format=markdown#cli-function-create) command.

| Option | Description |
| -------------- | -------------- |
| `--name` | The name of the function. Use a name that is unique within the project. This value is required. \n - The name must begin with a lowercase letter. \n - The name must end with a lowercase alphanumeric character. \n - The name must be 63 characters or fewer and can contain letters, numbers, and hyphens (-). | 
| `--build-source` | The URL of the Git repository that contains your source code; for example, `https://github.com/IBM/CodeEngine`. |
| `--build-context-dir` | The directory in the repository that contains the code. This value is optional. |
| `--runtime` | The runtime for the function. |
{: caption="Command description" caption-side="bottom"}

The following output shows the result of the **`function get`** command for this example, including information about the build.

Example output

```txt
Getting function 'myfun'
'...
OK

Name:          myfun  
Project Name:  sample  
Project ID:    abcdefgh-abcd-abcd-abcd-1a2b3c4d5e6f
Age:           27m  
Created:       2023-06-27T21:07:26Z  
Visibility:    public  
URL:           https://myfun.13c66hbi3rhz.us-south.codeengine.appdomain.cloud  
Internal URL:  http://myfun.13c66hbi3rhz.function.cluster.local  

Resources:    
  CPU:               0.25  
  Memory:            500M  
  Timeout:           60 seconds  
  Scale Down Delay:  1 seconds  
  Trusted profiles:  disabled  

Environment Variables:    
  Type     Name             Value  
  Literal  CE_API_BASE_URL  https://api.us-south.codeengine.cloud.ibm.com  
  Literal  CE_DOMAIN        us-south.codeengine.appdomain.cloud  
  Literal  CE_FUNCTION      myfun  
  Literal  CE_REGION        us-south  
  Literal  CE_SUBDOMAIN     13c66hbi3rhz  
  Literal  CE_PROJECT_ID    abcdefgh-abcd-abcd-abcd-1a2b3c4d5e6f

Build Information:    
  Build Run Name:     myfun-run-230111-111212718  
  Build Type:         git  
  Build Strategy:     codebundle-nodejs-22 
  Timeout:            600  
  Source:             https://github.com/IBM/CodeEngine  
  Context Directory:  /helloworld-samples/function-codebundle-nodejs    
                      
  Build Run Status:   Succeeded  
  Build Run Reason:   All Steps have completed executing  
  Run 'ibmcloud ce buildrun get -n myfun-run-230111-111212718' for details.  

Function Code:    
  Runtime:        nodejs-22
  Bundle Secret:  ce-auto-icr-us-south  
  Code Bundle:    cr://icr.io/ce--abcde-glxo4kabcde/function-myfun:230111-1532-vwo4o 
  Main:           main 

Status:  Ready  
URL:     https://myfun.13c66hbi3rhz.us-south.codeengine.appdomain.cloud 
```
{: screen}

Now that your function is created from repository source code, you can update the function to meet your needs by using the [**`ibmcloud ce function update`**](https://cloud.ibm.com/docs/codeengine?topic=codeengine-cli&format=markdown#cli-function-update) command. If you want to update your source to use with your function, you must provide the `--build-source` option on the **`function update`** command.

When your function is created from repository source code or from [local source](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-create-local&format=markdown) with the CLI, the resulting build run is not based on a build configuration. Build runs that complete are ultimately automatically deleted. Build runs that are not based on a build configuration are deleted after 1 hour if the build run is successful. If the build run is not successful, this build run is deleted after 24 hours. You can only display information about this build run with the CLI. You cannot view this build run in the console.
{: note}


## Including dependencies for your function
{: #fun-package-repo}

You can create functions in many different programming languages. When your function code grows complex, you can add code modules as dependencies for your function. Each language has its own modules to use with your function code. For example, Node.js dependencies are usually existing `npm` modules, whereas Python uses Python packages. These dependencies must be declared and created in a file with your source code

### Including modules for a Node.js function
{: #function-nodejs-dep-repo}

Create a function that includes a dependency for a specific Node.js module by creating a `package.json` file. In this case, both the source code and package file are located in the same folder.

1. Create your source code by writing your code into a `main.js` file. For example, copy the following code example into a file called `main.js`.

    ```javascript
    /**
    * The `main` function is the entry-point into the function.
    * It has one optional argument, which carries all the 
    * parameters the function was invoked with.
    */
    function main(params /* optional */) {
      // use third-party 'lorem-ipsum' package to generate random words
      const LoremIpsum = require("lorem-ipsum").LoremIpsum;
      const lorem = new LoremIpsum();

      // Since functions are invoked through http(s), we return an HTTP response.
      return {
        headers: { "Content-Type": "text/plain;charset=utf-8" },
        body: lorem.generateWords(10),
      };
    }

    // This step is necessary, if you gave your main function a different name.
    // We include it here for documentation purposes only.
    module.exports.main = main;
    ```
    {: codeblock}
  
2. Create a `package.json` file that contains the required dependencies for your function. For the previous code example, use the following contents for your `package.json` file.

    ```sh
    {
      "name": "function",
      "version": "1.0.0",
      "main": "main.js",
      "dependencies" : {
    		    "lorem-ipsum" : "2.0.8"
     	}
    }
    ```
    {: codeblock}


3. Create your files as a function in Code Engine. Both of previous files must be accessible in the repository. If they are in a private repository, create [private code repository access](https://cloud.ibm.com/docs/codeengine?topic=codeengine-code-repositories&format=markdown) and then provide that value with the `--build-git-repo-secret` option. If your files are located in a directory other than main, provide the path to the directory with the `--build-context-dir` option. The following example pulls the files from the `https://github.com/IBM/CodeEngine` public repository.
  
    ```sh
    ibmcloud ce fn create -n nodelorem -runtime nodejs --build-source https://github.com/IBM/CodeEngine --build-context-dir /helloworld-samples/function-codebundle-nodejs/
    ```
    {: pre}
  
4. Run the provided `fn get` command to find details about your function.
5. Invoke your function by pasting the URL into a web browser. Your browser displays a passage of `lorem ipsum`.

For more information about the `fn create` command and its options, see [Create a function](https://cloud.ibm.com/docs/codeengine?topic=codeengine-cli&format=markdown#cli-function-create).

### Including modules for a Python function
{: #function-python-dep-repo}

Create a function that includes a dependency for a specific Python module by creating a `requirements.txt` file. In this case, both the source code and requirements file are located in the same folder.

1. Create your function by saving your code into a `__main__.py` file 

    ```py
    # use third-party 'lorem-ipsum' package to generate random words
    from lorem_text import lorem

    # The `main` function is the entry-point into the function.
    # It has one optional argument, which carries all the 
    # parameters the function was invoked with.
    def main(params):
        words = 10

        # since functions are invoked through http(s), we return an HTTP response
        return {
          "headers": {
            "Content-Type": "text/plain;charset=utf-8",
        },
        "body": lorem.words(words),
    }
    def main(params):
         words = 10

         return {
              "headers": {
                  "Content-Type": "text/plain;charset=utf-8",
              },
              "body": lorem.words(words),
          }
    ```
    {: codeblock}


2. Create a `requirements.txt` containing your required dependencies for your function

    ```sh
    lorem-text
    ```
    {: codeblock}
  

3. Create your files as a function in Code Engine. Both of previous files must be accessible in the repository. If they are in a private repository, create [private code repository access](https://cloud.ibm.com/docs/codeengine?topic=codeengine-code-repositories&format=markdown) and then provide that value with the `--build-git-repo-secret` option. If your files are located in a directory other than main, provide the path to the directory with the `--build-context-dir` option. The following example pulls the files from the `https://github.com/IBM/CodeEngine` public repository.
  
    ```sh
    ibmcloud ce fn create -n pylorem -runtime python --build-source https://github.com/IBM/CodeEngine --build-context-dir /helloworld-samples/function-codebundle-python/
    ```
    {: pre}

4. Run the provided `fn get` command to find details about your function.
5. Invoke your function by pasting the URL into a web browser. Your browser displays a passage of `lorem ipsum`.
 

For more information about the `fn create` command and its options, see [Create a function](https://cloud.ibm.com/docs/codeengine?topic=codeengine-cli&format=markdown#cli-function-create).

## Next steps
{: #nextsteps-funsource}

- After your function is created, you can access your function by clicking **Test function** in the console or finding the URL for your function with the [**`function get`**](https://cloud.ibm.com/docs/codeengine?topic=codeengine-cli&format=markdown#cli-function-get) command.

- You can create a [custom domain mapping](https://cloud.ibm.com/docs/codeengine?topic=codeengine-domain-mappings&format=markdown) and assign it to your function.  

- After your function is created and deployed, you can update the function to meet your needs from the console or by using the [**`ibmcloud ce function update`**](https://cloud.ibm.com/docs/codeengine?topic=codeengine-cli&format=markdown#cli-function-update) command. If you want to update your source to use with your function, you must provide the `--build-source` option on the **`function update`** command.

After your function is created, you can update your function and its referenced code by using *any* of the following ways, independent of how you created or previously updated your function:

- If you have an existing code bundle, then you need to provide only a reference to the image, which points to the location of your container registry when you deploy your app. For more information, see [Creating function workloads from existing code bundles](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-create-existing&format=markdown).

    If you created your function by using the **`function create`** command and you specified the `--build-source` option to build the code bundle from local or repository source, and you want to change your function to point to a different code bundle, you must first remove the association of the build from your function. For example, run `ibmcloud ce function update -n FUN_NAME --build-clear`. After you remove the association of the build from your function, you can update the function to reference a different image. 
    {: note}

- If you are starting with source code that resides in a Git repository, you can choose to let Code Engine to build the code bundle from your source and create your function with a **single** operation. In this scenario, Code Engine uploads your code bundle to IBM Cloud&reg; Container Registry. To learn more, see [Creating your function from repository source code](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-create-repo&format=markdown).

- If you are starting with source code that resides on a local workstation, you can choose for Code Engine to build the code bundle from your source and create your function with a **single** CLI command. In this scenario, Code Engine uploads your source code and code bundle to IBM Cloud&reg; Container Registry. 

    For example, you might choose for Code Engine to build your local source while you evolve the development of your source for the function. Then, after the code bundle is matured, you can update your function to reference the specific code bundle that you want. You can repeat this process as needed.



Looking for more code examples? Check out the [Samples for IBM Cloud Code Engine GitHub repo](https://github.com/IBM/CodeEngine){: external}.
{: tip}