Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/42.changed.srt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated the git configuration to use a single `checkout_code` property, which is output as is in the jenkinsfile
126 changes: 65 additions & 61 deletions documentation/archiveconfig.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,66 @@
# ArchiveConfig

```
Archive feature for the Jenkins File Generator.
This feature allows to archive the artifacts or build products created by the jenkins pipeline.
It also allows to upload the archives to an S3 bucket.

Both actions have the same behavior:
1. The local folder will be copied over to the shared folder / s3 bucket with the current date
2. If a directory with the same name already exists, an incremental suffix will be added (_01, _02, etc...)
3. Only the specified number of most recent directories in the parent folder will be kept, older ones will be deleted.
4. Optionally, a slack notification can be sent on completion of the action.
```
* **additional_node_name**: Additional jenkins node tags to use if you want the archiving tasks to be executed on specific nodes. ( Type: `Optional[str]` Default: `None` )

* **rotate_archives**: Configuration for rotating archives ( (Required) Type: `RotateArchivesConfig` )
* **enabled**: Enable or disable the action of rotating the archives ( Type: `bool` Default: `False` )

* **directory_path**: Path to the directory to rename with the current date ( (Required) Type: `<class 'pathlib.Path'>` )

* **keep_count**: Number of directories to keep in the parent folder after directory_path has been renamed ( Type: `int` Default: `10` )

* **folder_output_file_name**: Optional path to text file where the new directory name will be written to be re-used by other tasks ( Type: `Optional[pathlib.Path]` Default: `None` )

* **slack**: Slack configuration ( Type: `Optional[features.archive.SlackNotificationConfig]` Default: `None` )
* **enabled**: Enable or disable Slack notifications ( Type: `bool` Default: `False` )

* **channel**: Slack channel to send notifications to ( Type: `str` Default: `` )

* **message_template**: Template for the notification message ( Type: `str` Default: `` )



* **upload_archives**: Configuration for uploading archives ( (Required) Type: `UploadArchivesConfig` )
* **enabled**: Enable or disable the action of uploading the archives ( Type: `bool` Default: `False` )

* **local_folder**: Path to the local folder containing the archives to upload. Optional. If you're using rotate_archives, jenkins will set the local folder path with the contents of output_file. ( Type: `Optional[pathlib.Path]` Default: `None` )

* **bucket_name**: Name of the S3 bucket to upload the archives to ( Type: `str` Default: `` )

* **region**: AWS region where the S3 bucket is located ( Type: `str` Default: `` )

* **access_key**: Access key for AWS S3 authentication ( Type: `str` Default: `` )

* **secret_key**: Secret key for AWS S3 authentication ( Type: `str` Default: `` )

* **destination_folder**: Destination folder in the S3 bucket where the archives will be uploaded ( Type: `str` Default: `` )

* **keep_count**: Number of archives to keep in the S3 bucket. If lower than 1, all archives will be kept. ( Type: `int` Default: `-1` )

* **output_file_name**: Optional path to text file where the download URLs of uploaded archives will be written ( Type: `Optional[pathlib.Path]` Default: `None` )

* **slack**: Slack configuration ( Type: `Optional[features.archive.SlackNotificationConfig]` Default: `None` )
* **enabled**: Enable or disable Slack notifications ( Type: `bool` Default: `False` )

* **channel**: Slack channel to send notifications to ( Type: `str` Default: `` )

* **message_template**: Template for the notification message ( Type: `str` Default: `` )



# ArchiveConfig

```
Archive feature for the Jenkins File Generator.
This feature allows to archive the artifacts or build products created by the jenkins pipeline.
It also allows to upload the archives to an S3 bucket.
It requires the python feature to work, and that you have in the requirements of your python folder in the project
a reference to the package GameDevTools.

Both actions have the same behavior:
1. The local folder will be copied over to the shared folder / s3 bucket with the current date
2. If a directory with the same name already exists, an incremental suffix will be added (_01, _02, etc...)
3. Only the specified number of most recent directories in the parent folder will be kept, older ones will be deleted.
4. Optionally, a slack notification can be sent on completion of the action.
```
* **additional_node_name**: Additional jenkins node tags to use if you want the archiving tasks to be executed on specific nodes. ( Type: `Optional[str]` Default: `None` )

* **rotate_archives**: Configuration for rotating archives ( (Required) Type: `RotateArchivesConfig` )
* **enabled**: Enable or disable the action of rotating the archives ( Type: `bool` Default: `False` )

* **source_directory**: Path to the source directory where to move the files from ( (Required) Type: `<class 'pathlib.Path'>` )

* **destination_directory**: Path to the destination directory where to move the files to (in a new folder based on the current date ( (Required) Type: `<class 'pathlib.Path'>` )

* **keep_count**: Number of directories to keep in the parent folder after directory_path has been renamed ( Type: `int` Default: `10` )

* **folder_output_file_name**: Optional path to text file where the new directory name will be written to be re-used by other tasks ( Type: `Optional[pathlib.Path]` Default: `None` )

* **slack**: Slack configuration ( Type: `Optional[features.archive.SlackNotificationConfig]` Default: `None` )
* **enabled**: Enable or disable Slack notifications ( Type: `bool` Default: `False` )

* **channel**: Slack channel to send notifications to ( Type: `str` Default: `` )

* **message_template**: Template for the notification message ( Type: `str` Default: `` )



* **upload_archives**: Configuration for uploading archives ( (Required) Type: `UploadArchivesConfig` )
* **enabled**: Enable or disable the action of uploading the archives ( Type: `bool` Default: `False` )

* **local_folder**: Path to the local folder containing the archives to upload. Optional. If you're using rotate_archives, jenkins will set the local folder path with the contents of output_file. ( Type: `Optional[pathlib.Path]` Default: `None` )

* **bucket_name**: Name of the S3 bucket to upload the archives to ( Type: `str` Default: `` )

* **region**: AWS region where the S3 bucket is located ( Type: `str` Default: `` )

* **access_key**: Access key for AWS S3 authentication ( Type: `str` Default: `` )

* **secret_key**: Secret key for AWS S3 authentication ( Type: `str` Default: `` )

* **destination_folder**: Destination folder in the S3 bucket where the archives will be uploaded ( Type: `str` Default: `` )

* **keep_count**: Number of archives to keep in the S3 bucket. If lower than 1, all archives will be kept. ( Type: `int` Default: `-1` )

* **output_file_name**: Optional path to text file where the download URLs of uploaded archives will be written ( Type: `Optional[pathlib.Path]` Default: `None` )

* **slack**: Slack configuration ( Type: `Optional[features.archive.SlackNotificationConfig]` Default: `None` )
* **enabled**: Enable or disable Slack notifications ( Type: `bool` Default: `False` )

* **channel**: Slack channel to send notifications to ( Type: `str` Default: `` )

* **message_template**: Template for the notification message ( Type: `str` Default: `` )



[Back to main page](index.md)
17 changes: 2 additions & 15 deletions documentation/gitconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,9 @@
```
This module defines the Git-related features and configurations for Jenkins pipelines.
```
* **use_simple_checkout**: Set to true to uses a simple `checkout scm`. Otherwise fine-tune the checkout with the other properties ( Type: `bool` Default: `True` )

* **checkout**: The checkout configuration. If use_simple_checkout is true, this will be ignored. ( Type: `Optional[features.git.GitCheckoutConfig]` Default: `None` )
* **branch_name**: The branch name to checkout ( (Required) Type: `str` )

* **extensions**: The extensions to use for the checkout ( Type: `Dict[str, GitExtensionConfig]` Default: `{}` )


* **user_remote_config**: The user remote configuration. ( (Required) Type: `UserRemoteConfig` )
* **credentials_id**: The credentials ID and URL for the remote repository. ( (Required) Type: `CredentialsIdConfig` )
* **id**: The jenkins credential id to use to connect to the url. ( (Required) Type: `str` )

* **url**: The git url to use to checkout the repository. ( (Required) Type: `str` )


* **checkout_code**: This property will be output in the jenkinsfile as is. You can generate a valid code by using the pipeline syntax page of Jenkins. ( Type: `str` Default: `checkout scm` )

* **pre_checkout_tasks**: List of tasks to run before running the checkout. ( Type: `Optional[List[str]]` Default: `[]` )

* **retry_count**: Set to a value greater than 1 to try to checkout multiple times. This can help avoid the job to fail in some circumstances (for example with a github app) ( Type: `Optional[int]` Default: `1` )

Expand Down
70 changes: 35 additions & 35 deletions documentation/plasticscmconfig.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# PlasticSCMConfig

```
This module defines the PlasticSCM-related features and configurations for Jenkins pipelines.
```
* **checkout**: The checkout configuration. If use_simple_checkout is true, this will be ignored. ( (Required) Type: `PlasticSCMCheckoutConfig` )
* **branch**: The branch name to checkout, overriden by shelveset and label. ( (Required) Type: `str` )

* **changeset**: The changeset to checkout, overriden by shelveset and label. ( Type: `Optional[str]` Default: `None` )

* **shelveset**: The shelveset to checkout, overrides branch and changeset, overriden by label. ( Type: `Optional[str]` Default: `None` )

* **label**: The label to checkout, overrides branch, changeset and shelveset. ( Type: `Optional[str]` Default: `None` )

* **changelog**: Enable or Disable 'Include in changelog'. ( Type: `Optional[bool]` Default: `True` )

* **poll**: Enable or Disable 'Include in polling'. ( Type: `Optional[bool]` Default: `False` )

* **remote_config**: The remote configuration. ( (Required) Type: `RemoteConfig` )
* **repository**: The PlasticSCM repository name. ( (Required) Type: `str` )

* **server**: The PlasticSCM server port. ( (Required) Type: `str` )


* **cleanup**: Cleanup settings of the repository. (MINIMAL,STANDARD,FULL,DELETE) ( Type: `Optional[str]` Default: `STANDARD` )

* **directory**: The workspace subdirectory to clone the repo, required if you use multiple workspaces. ( Type: `Optional[str]` Default: `None` )

* **credentials_config**: The crendentials configuration. ( Type: `Optional[features.plasticscm.CredentialsConfig]` Default: `None` )
* **working_mode**: The jenkins credential id working mode. (NONE,UP,LDAP) ( (Required) Type: `str` )

* **credentials_id**: The jenkins credentials id to use to connect to the remote. ( (Required) Type: `str` )



# PlasticSCMConfig
```
This module defines the PlasticSCM-related features and configurations for Jenkins pipelines.
```
* **checkout**: The checkout configuration. If use_simple_checkout is true, this will be ignored. ( (Required) Type: `PlasticSCMCheckoutConfig` )
* **branch**: The branch name to checkout, overriden by shelveset and label. ( (Required) Type: `str` )
* **changeset**: The changeset to checkout, overriden by shelveset and label. ( Type: `Optional[str]` Default: `None` )
* **shelveset**: The shelveset to checkout, overrides branch and changeset, overriden by label. ( Type: `Optional[str]` Default: `None` )
* **label**: The label to checkout, overrides branch, changeset and shelveset. ( Type: `Optional[str]` Default: `None` )
* **changelog**: Enable or Disable 'Include in changelog'. ( Type: `Optional[bool]` Default: `True` )
* **poll**: Enable or Disable 'Include in polling'. ( Type: `Optional[bool]` Default: `False` )
* **remote_config**: The remote configuration. ( (Required) Type: `RemoteConfig` )
* **repository**: The PlasticSCM repository name. ( (Required) Type: `str` )
* **server**: The PlasticSCM server port. ( (Required) Type: `str` )
* **cleanup**: Cleanup settings of the repository. (MINIMAL,STANDARD,FULL,DELETE) ( Type: `Optional[str]` Default: `STANDARD` )
* **directory**: The workspace subdirectory to clone the repo, required if you use multiple workspaces. ( Type: `Optional[str]` Default: `None` )
* **credentials_config**: The crendentials configuration. ( Type: `Optional[features.plasticscm.CredentialsConfig]` Default: `None` )
* **working_mode**: The jenkins credential id working mode. (NONE,UP,LDAP) ( (Required) Type: `str` )
* **credentials_id**: The jenkins credentials id to use to connect to the remote. ( (Required) Type: `str` )
[Back to main page](index.md)
26 changes: 13 additions & 13 deletions documentation/pythonconfig.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# PythonConfig

```
This module defines the python feature for Jenkins pipelines.

This feature will create 2 additional functions:
* activatePythonEnvironment which will call the script defined in the config with the venv_activation_script_path
* executePythonScript which will execute an executable in the virtual environment's Scripts folder
```
* **venv_activation_script_path**: The path to the virtual environment activation script.This must point to a script that can be sourced to activate the virtual environment. ( Type: `Optional[str]` Default: `None` )

* **venv_folder**: The path to the virtual environment folder after it has been created by executing venv_activation_script_path. ( (Required) Type: `str` )

# PythonConfig
```
This module defines the python feature for Jenkins pipelines.
This feature will create 2 additional functions:
* activatePythonEnvironment which will call the script defined in the config with the venv_activation_script_path
* executePythonScript which will execute an executable in the virtual environment's Scripts folder
```
* **venv_activation_script_path**: The path to the virtual environment activation script.This must point to a script that can be sourced to activate the virtual environment. ( Type: `Optional[str]` Default: `None` )
* **venv_folder**: The path to the virtual environment folder after it has been created by executing venv_activation_script_path. ( (Required) Type: `str` )
[Back to main page](index.md)
98 changes: 6 additions & 92 deletions src/generator/features/git.py
Original file line number Diff line number Diff line change
@@ -1,106 +1,20 @@
"""This module defines the Git-related features and configurations for Jenkins pipelines."""

from abc import ABC
from typing import Any, Dict, List, Optional, Type

from pydantic import BaseModel, Field, field_validator
from pydantic import Field

from generator.core.base_feature import BaseFeature, FeatureConfig


class CredentialsIdConfig(BaseModel):
"""Configuration for credentials ID used in Git operations."""

id: str = Field(description="The jenkins credential id to use to connect to the url.")
url: str = Field(description="The git url to use to checkout the repository.")


class UserRemoteConfig(BaseModel):
"""Configuration for user remote settings in Git operations."""

credentials_id: CredentialsIdConfig = Field(description="The credentials ID and URL for the remote repository.")


class GitExtensionConfig(BaseModel, ABC):
"""Base class for Git extension configurations."""

def should_emit(self) -> bool:
"""Determine if this extension should emit text in the Jenkinsfile."""
return True

@classmethod
def get_class_name(cls) -> str:
"""Class method version - returns the class name without 'Config' suffix"""
class_name = cls.__name__
if class_name.endswith("Config"):
return class_name[:-6]
return class_name


class SubmoduleOptionConfig(GitExtensionConfig):
"""Configuration for submodule options in Git operations."""

disableSubmodules: Optional[bool] = None
parentCredentials: Optional[bool] = None
recursiveSubmodules: Optional[bool] = None
reference: Optional[str] = None
timeout: Optional[int] = None
trackingSubmodules: Optional[bool] = None


class GitLFSPullConfig(GitExtensionConfig):
"""Configuration for Git LFS pull."""

enabled: bool = Field(default=False, description="Set to true to pull from LFS.")

def should_emit(self) -> bool:
return False


class CheckoutOptionConfig(GitExtensionConfig):
"""Configuration for checkout options."""

timeout: Optional[int] = Field(default=None, description="Timeout for the checkout operation in seconds.")


class GitCheckoutConfig(BaseModel):
"""Configuration for the Git checkout operation."""

branch_name: str = Field(description="The branch name to checkout")
extensions: Dict[str, GitExtensionConfig] = Field(default={}, description="The extensions to use for the checkout")
user_remote_config: UserRemoteConfig = Field(description="The user remote configuration.")

@field_validator("extensions", mode="before")
@classmethod
def validate_extensions(cls, raw_exts: Dict[str, Any]) -> Dict[str, GitExtensionConfig]:
"""Validate and parse the extensions dictionary."""
parsed_exts: Dict[str, GitExtensionConfig] = {}
for key, value in raw_exts.items():

def get_config_class(yaml_key: str) -> Type[GitExtensionConfig]:
class_name = yaml_key + "Config"
model_cls = globals().get(class_name)
if model_cls is None:
raise ValueError(f"Unknown extension key: {yaml_key}")
return model_cls # type: ignore[no-any-return]

model_cls = get_config_class(key)
if model_cls is None:
raise ValueError(f"Unknown extension key: {key}")
parsed_exts[key] = model_cls(**value)
return parsed_exts


class GitConfig(FeatureConfig):
"""Configuration model for the git properties."""

use_simple_checkout: bool = Field(
default=True,
description="Set to true to uses a simple `checkout scm`. Otherwise fine-tune the checkout with the other properties",
)
checkout: Optional[GitCheckoutConfig] = Field(
default=None,
description="The checkout configuration. If use_simple_checkout is true, this will be ignored.",
checkout_code: str = Field(
default="checkout scm",
description=(
"This property will be output in the jenkinsfile as is. You can generate a valid code by using the pipeline syntax page of Jenkins."
),
)
pre_checkout_tasks: Optional[List[str]] = Field(
default=[],
Expand Down
Loading
Loading