diff --git a/.changelog/42.changed.srt b/.changelog/42.changed.srt new file mode 100644 index 0000000..dae2279 --- /dev/null +++ b/.changelog/42.changed.srt @@ -0,0 +1 @@ +Updated the git configuration to use a single `checkout_code` property, which is output as is in the jenkinsfile \ No newline at end of file diff --git a/documentation/archiveconfig.md b/documentation/archiveconfig.md index 59f284f..0368e86 100644 --- a/documentation/archiveconfig.md +++ b/documentation/archiveconfig.md @@ -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: `` ) - - * **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: `` ) + + * **destination_directory**: Path to the destination directory where to move the files to (in a new folder based on the current date ( (Required) Type: `` ) + + * **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) \ No newline at end of file diff --git a/documentation/gitconfig.md b/documentation/gitconfig.md index cea2655..72781ac 100644 --- a/documentation/gitconfig.md +++ b/documentation/gitconfig.md @@ -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` ) diff --git a/documentation/plasticscmconfig.md b/documentation/plasticscmconfig.md index be45649..943bc2e 100644 --- a/documentation/plasticscmconfig.md +++ b/documentation/plasticscmconfig.md @@ -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) \ No newline at end of file diff --git a/documentation/pythonconfig.md b/documentation/pythonconfig.md index af11bdc..97228ba 100644 --- a/documentation/pythonconfig.md +++ b/documentation/pythonconfig.md @@ -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) \ No newline at end of file diff --git a/src/generator/features/git.py b/src/generator/features/git.py index 885c9e8..e2caab3 100644 --- a/src/generator/features/git.py +++ b/src/generator/features/git.py @@ -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=[], diff --git a/src/generator/templates/git.mako b/src/generator/templates/git.mako index 3f02a94..407eea7 100644 --- a/src/generator/templates/git.mako +++ b/src/generator/templates/git.mako @@ -9,33 +9,7 @@ def projectCheckout() { % if feature_config.retry_count > 1: retry(count: ${feature_config.retry_count}) { % endif - -% if feature_config.use_simple_checkout: - checkout scm -% else: - checkout([ - $class: 'GitSCM', - branches: [ ['name': '${feature_config.checkout.branch_name}' ] ], - extensions: [ - % for key, options in feature_config.checkout.extensions.items(): - <% should_emit = options.should_emit() %>\ -[ $class: '${options.get_class_name()}'${',' if should_emit else ''}\ - % if should_emit: - \ - % for k, v in options.dict().items(): -${k}: ${groovy.write_groovy_repr(v)}${',' if not loop.last else ''}\ - % endfor - \ - % endif -], - % endfor - ], - userRemoteConfigs: [ - [ credentialsId: '${feature_config.checkout.user_remote_config.credentials_id.id}', url: '${feature_config.checkout.user_remote_config.credentials_id.url}' ] - ] - ]) -% endif - + ${feature_config.checkout_code} % if feature_config.retry_count > 1: } % endif